Пример #1
0
 public void SaveBlog(Blog blog)
 {
     if (blog.BlogID == 0)
     {
         context.Blogs.Add(blog);
     }
     else
     {
         Blog dbEntry = context.Blogs
                        .FirstOrDefault(p => p.BlogID == blog.BlogID);
         if (dbEntry != null)
         {
             dbEntry.Title         = blog.Title;
             dbEntry.Description   = blog.Description;
             dbEntry.TitleRu       = blog.TitleRu;
             dbEntry.DescriptionRu = blog.DescriptionRu;
             dbEntry.TitleUz       = blog.TitleUz;
             dbEntry.DescriptionUz = blog.DescriptionUz;
             dbEntry.CreatedDate   = blog.CreatedDate;
             if (blog.ImageUrl != null)
             {
                 dbEntry.ImageUrl = blog.ImageUrl;
             }
         }
     }
     context.SaveChanges();
 }
Пример #2
0
 public void SaveCert(Certificate cert)
 {
     if (cert.CertID == 0)
     {
         context.Certificates.Add(cert);
     }
     else
     {
         Certificate dbEntry = context.Certificates
                               .FirstOrDefault(p => p.CertID == cert.CertID);
         if (dbEntry != null)
         {
             if (cert.CertPath != null)
             {
                 dbEntry.CertPath = cert.CertPath;
             }
             if (cert.StaffId != 0)
             {
                 dbEntry.StaffId = cert.StaffId;
             }
             if (cert.CertName != null)
             {
                 dbEntry.CertName = cert.CertName;
             }
         }
     }
     context.SaveChanges();
 }
Пример #3
0
        public static void EnsurePopulatedIdentRole(IApplicationBuilder app)
        {
            AppIdentityDbContext dbContext = app.ApplicationServices
                                             .GetRequiredService <AppIdentityDbContext>();

            if (!dbContext.Roles.Any())
            {
                foreach (var role in Roles)
                {
                    dbContext.Roles.Add(role);
                    dbContext.SaveChanges();
                }
            }

            if (!dbContext.UserRoles.Any())
            {
                var userRole = new IdentityUserRole <string>
                {
                    UserId = dbContext.Users.Single(r => r.UserName == "SuperAdmin").Id,
                    RoleId = dbContext.Roles.Single(r => r.Name == "SuperAdmin").Id
                };
                dbContext.UserRoles.Add(userRole);
                dbContext.SaveChanges();
            }
        }
Пример #4
0
 public void SaveTag(InfoTag Tag)
 {
     if (Tag.id == 0)
     {
         context.InfoTags.Add(Tag);
     }
     else
     {
         InfoTag dbEntry = context.InfoTags
                           .FirstOrDefault(p => p.id == Tag.id);
         if (dbEntry != null)
         {
             dbEntry.TagName = Tag.TagName;
         }
     }
     context.SaveChanges();
 }
Пример #5
0
 public void SaveImage(Gallery image)
 {
     if (image.ImageID == 0)
     {
         context.Images.Add(image);
     }
     else
     {
         Gallery dbEntry = context.Images
                           .FirstOrDefault(p => p.ImageID == image.ImageID);
         if (dbEntry != null)
         {
             dbEntry.ImagePath  = image.ImagePath;
             dbEntry.UploadDate = image.UploadDate;
             dbEntry.InfoTags   = image.InfoTags;
         }
     }
     context.SaveChanges();
 }
Пример #6
0
 public void SaveStaff(Staff staff)
 {
     if (staff.StaffID == 0)
     {
         context.Staffs.Add(staff);
     }
     else
     {
         Staff dbEntry = context.Staffs
                         .FirstOrDefault(p => p.StaffID == staff.StaffID);
         if (dbEntry != null)
         {
             dbEntry.Name          = staff.Name;
             dbEntry.Surname       = staff.Surname;
             dbEntry.FullInfo      = staff.FullInfo;
             dbEntry.Description   = staff.Description;
             dbEntry.NameRu        = staff.NameRu;
             dbEntry.SurnameRu     = staff.SurnameRu;
             dbEntry.FullInfoRu    = staff.FullInfoRu;
             dbEntry.DescriptionRu = staff.DescriptionRu;
             dbEntry.NameUz        = staff.NameUz;
             dbEntry.SurnameUz     = staff.SurnameUz;
             dbEntry.FullInfoUz    = staff.FullInfoUz;
             dbEntry.DescriptionUz = staff.DescriptionUz;
             if (staff.ImageUrl != null)
             {
                 dbEntry.ImageUrl = staff.ImageUrl;
             }
             if (staff.Certificates != null)
             {
                 dbEntry.Certificates = staff.Certificates;
             }
         }
     }
     context.SaveChanges();
 }