DocSpace-client/common/ASC.Core.Common/EF/Model/User/UserPhoto.cs

84 lines
2.6 KiB
C#
Raw Normal View History

2020-09-06 22:49:03 +00:00
using ASC.Core.Common.EF.Model;
using Microsoft.EntityFrameworkCore;
2020-08-21 02:34:37 +00:00
using System;
2019-11-25 09:49:12 +00:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ASC.Core.Common.EF
{
[Table("core_userphoto")]
2019-12-17 13:01:59 +00:00
public class UserPhoto : BaseEntity
2019-11-25 09:49:12 +00:00
{
public int Tenant { get; set; }
[Key]
public Guid UserId { get; set; }
public byte[] Photo { get; set; }
2019-12-17 13:01:59 +00:00
2020-02-21 12:38:04 +00:00
public override object[] GetKeys()
2019-12-17 13:01:59 +00:00
{
return new object[] { UserId };
}
2019-11-25 09:49:12 +00:00
}
2020-08-21 02:34:37 +00:00
public static class UserPhotoExtension
{
2020-09-06 22:49:03 +00:00
public static ModelBuilderWrapper AddUserPhoto(this ModelBuilderWrapper modelBuilder)
{
modelBuilder
.Add(MySqlAddUserPhoto, Provider.MySql)
.Add(PgSqlAddUserPhoto, Provider.Postrge);
return modelBuilder;
}
2020-08-21 02:34:37 +00:00
public static void MySqlAddUserPhoto(this ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserPhoto>(entity =>
{
entity.HasKey(e => e.UserId)
.HasName("PRIMARY");
entity.ToTable("core_userphoto");
entity.HasIndex(e => e.Tenant)
.HasName("tenant");
entity.Property(e => e.UserId)
.HasColumnName("userid")
.HasColumnType("varchar(38)")
.HasCharSet("utf8")
.HasCollation("utf8_general_ci");
entity.Property(e => e.Photo)
.IsRequired()
.HasColumnName("photo")
.HasColumnType("mediumblob");
entity.Property(e => e.Tenant).HasColumnName("tenant");
});
}
public static void PgSqlAddUserPhoto(this ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserPhoto>(entity =>
{
entity.HasKey(e => e.UserId)
.HasName("core_userphoto_pkey");
entity.ToTable("core_userphoto", "onlyoffice");
entity.HasIndex(e => e.Tenant)
.HasName("tenant_core_userphoto");
entity.Property(e => e.UserId)
.HasColumnName("userid")
.HasMaxLength(38);
entity.Property(e => e.Photo)
.IsRequired()
.HasColumnName("photo");
entity.Property(e => e.Tenant).HasColumnName("tenant");
});
}
}
2019-11-25 09:49:12 +00:00
}