public bool EditSeller(Seller rec) { using (ManaCenaEntities context = new ManaCenaEntities()) { context.Sellers.Add(rec); if (rec.Id > 0) { context.Entry(rec).State = System.Data.Entity.EntityState.Modified; if (rec.SellerImage != null) { if (rec.SellerImage.Id > 0) { context.Entry(rec.SellerImage).State = System.Data.Entity.EntityState.Modified; } else { context.Entry(rec.SellerImage).State = System.Data.Entity.EntityState.Added; } } } else { context.Entry(rec).State = System.Data.Entity.EntityState.Added; context.Entry(rec.SellerImage).State = System.Data.Entity.EntityState.Added; rec.SellerImage.Id = 0; } context.SaveChanges(); } return(true); }
public bool EditLocation(Location rec) { using (ManaCenaEntities context = new ManaCenaEntities()) { context.Locations.Add(rec); if (rec.Id > 0) { context.Entry(rec).State = System.Data.Entity.EntityState.Modified; } else { context.Entry(rec).State = System.Data.Entity.EntityState.Added; } context.SaveChanges(); } return(true); }
public bool EditCathegoryType(CathegoryType rec) { using (ManaCenaEntities context = new ManaCenaEntities()) { context.CathegoryTypes.Add(rec); if (rec.Id > 0) { context.Entry(rec).State = System.Data.Entity.EntityState.Modified; } else { context.Entry(rec).State = System.Data.Entity.EntityState.Added; } context.SaveChanges(); } return(true); }
public bool DeleteItem(int id) { using (ManaCenaEntities context = new ManaCenaEntities()) { var rec = new Product { Id = id }; context.Entry(rec).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } return(true); }
public bool EditItem(Product rec) { //ProductLocation peredajotsa, sledujushije shagi: //1) Proverj ne perezapisivajutsa li oni //2) Proverj, chtobi stiralis vse predidushije esli v nachale bili XX/X/XXX a potm pusto //2.1.) Sohranenije novoj zapisi //3) Otobrazhenije // 4) otobrazhenije v Detailes using (ManaCenaEntities context = new ManaCenaEntities()) { //dell all Locations (if any) context.ProductLocations.RemoveRange(context.ProductLocations.Where(o => o.ProductId == rec.Id)); if (rec.ProductLocations.Count == context.Locations.Count(o => o.SellerId == rec.SellerId)) { rec.ProductLocations = null; } context.Products.Add(rec); if (rec.Id > 0) { context.Entry(rec).State = System.Data.Entity.EntityState.Modified; if (rec.ProductImage != null) { context.Entry(rec.ProductImage).State = System.Data.Entity.EntityState.Modified; } if (rec.ProductImageSmall != null) { context.Entry(rec.ProductImageSmall).State = System.Data.Entity.EntityState.Modified; } else { rec.ProductImageSmall = new ProductImageSmall(); } rec.ProductImageSmall.Image = Helpers.ImageHelper.ResizeImage(rec.ProductImage.Image); //// if same image in DB already, do not overwrite then //var image = context.ProductImages.Where(o => o.Id == rec.ProductImageId).First(); //if (rec.ProductImage != null && image != null && image.Image != rec.ProductImage.Image) //{ // rec.ProductImageSmall = new ProductImageSmall { Image = Helpers.ImageHelper.ResizeImage(rec.ProductImage.Image) }; //} } else { context.Entry(rec).State = System.Data.Entity.EntityState.Added; context.Entry(rec.ProductImage).State = System.Data.Entity.EntityState.Added; rec.ProductImage.Id = 0; rec.ProductImageSmall = new ProductImageSmall { Image = Helpers.ImageHelper.ResizeImage(rec.ProductImage.Image) }; } context.SaveChanges(); } return(true); }