public static Users GetByLogin(string login) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { return(dbContext.Users.FirstOrDefault(u => u.Login == login)); } }
public static void AddOrUpdate(Pyramid.Entity.Image image = null, HttpPostedFileBase files = null) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { if (files != null) { if (image == null && files != null) { Images efImg = SaveFile(files); dbContext.Images.Add(efImg); } else { if (image != null) { var efImage = dbContext.Images.Find(image.Id); if (efImage != null) { efImage.ImgAlt = image.ImgAlt; efImage.Title = image.Title; } } } } dbContext.SaveChanges(); } }
public static void AddOrUpdate(int productId, Pyramid.Entity.ProductValue prValue) { if (productId != 0 && prValue != null) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { if (prValue.Id == 0) { dbContext.ProductValues.Add(new ProductValues() { Id = prValue.Id, Key = prValue.Key, ProductId = productId, Value = prValue.Value }); } else { var efEntiry = dbContext.ProductValues.Find(prValue.Id); if (efEntiry != null) { dbContext.Entry(efEntiry).CurrentValues.SetValues(prValue); } } dbContext.SaveChanges(); } } }
public static int GetCountByProductId(int productId) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { int amount = dbContext.ProductValues.Where(i => i.ProductId == productId).Count(); return(amount); } }
public static ICollection <Pyramid.Entity.Filter> GetAll() { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { return(dbContext.Filters.Select(f => new Pyramid.Entity.Filter() { Title = f.Title, Id = f.Id }).ToList()); } }
public static void Delete(int id) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { var efEntity = dbContext.ProductValues.Find(id); if (efEntity != null) { dbContext.ProductValues.Remove(efEntity); dbContext.SaveChanges(); } } }
public static ICollection <Pyramid.Entity.ProductValue> GetAll(int productId) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { return(dbContext.ProductValues.Where(p => p.ProductId == productId).Select(i => new Pyramid.Entity.ProductValue() { Id = i.Id, Key = i.Key, ProductId = i.ProductId, Value = i.Value }).ToList()); } }
public static Pyramid.Entity.Filter Get(int id) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { var entity = dbContext.Filters.Find(id); if (entity != null) { return(new Pyramid.Entity.Filter() { Id = entity.Id, Title = entity.Title }); } return(null); } }
public static ICollection <Pyramid.Entity.Image> GetAll() { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { var t = dbContext.Images.Select(image => new Pyramid.Entity.Image() { Id = image.Id, ImgAlt = image.ImgAlt, PathInFileSystem = image.PathInFileSystem, ServerPathImg = image.ServerPathImg, Title = image.Title }).ToList(); t.Reverse(); return(t); } }
//private static readonly DataContext dbContext = new DataContext(); public static int AddOrUpdate(Users user) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { if (user.Id == 0) { dbContext.Users.Add(user); } else { var efuser = dbContext.Users.Find(user.Id); dbContext.Entry(efuser).CurrentValues.SetValues(user); } dbContext.SaveChanges(); return(user.Id); } }
public static void AddOrDefault(Pyramid.Entity.Filter filter) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { if (filter.Id == 0) { dbContext.Filters.Add(new Filters() { Title = filter.Title, }); } else { var efFilter = dbContext.Filters.Find(filter.Id); dbContext.Entry(efFilter).CurrentValues.SetValues(filter); } dbContext.SaveChanges(); } }
public static Pyramid.Entity.Image Get(int id) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { var image = dbContext.Images.Find(id); if (image != null) { return(new Pyramid.Entity.Image() { Id = image.Id, ImgAlt = image.ImgAlt, PathInFileSystem = image.PathInFileSystem, ServerPathImg = image.ServerPathImg, Title = image.Title }); } return(null); } }
public static void Delete(int id) { using (PyramidFinalContext dbContext = new PyramidFinalContext()) { var entity = dbContext.Images.Find(id); if (entity != null) { entity.HomeEntity.Clear(); entity.BannerWithPoints.Clear(); entity.CategoryImages.Clear(); entity.EventBanners.Clear(); entity.EventImages.Clear(); entity.Recommendations.Clear(); dbContext.SaveChanges(); DeleteFile(entity.PathInFileSystem); dbContext.Images.Remove(entity); } dbContext.SaveChanges(); } }