public ShopMobilesM Save(ShopMobilesM shopMobiles) { Shop_Mobiles shopMobilesDb = new Shop_Mobiles() { MobileId = shopMobiles.MobileId, MobilesLeft = shopMobiles.MobilesLeft, ShopId = shopMobiles.ShopId, Price = shopMobiles.Price, }; Context.Shop_Mobiles.Add(shopMobilesDb); Context.SaveChanges(); shopMobiles.Id = shopMobilesDb.Id; return(shopMobiles); }
public ShopMobilesM Delete(int id) { Shop_Mobiles shopMobiles = Context.Shop_Mobiles.SingleOrDefault(x => x.Id == id); Context.Shop_Mobiles.Remove(shopMobiles); Context.SaveChanges(); return(new ShopMobilesM() { Id = shopMobiles.Id, MobileId = shopMobiles.MobileId ?? -1, MobilesLeft = shopMobiles.MobilesLeft ?? 0, ShopId = shopMobiles.ShopId ?? -1, Price = shopMobiles.Price ?? 0, }); }
public ShopMobilesM FindById(int id) { Shop_Mobiles shopMobiles = Context.Shop_Mobiles.SingleOrDefault(x => x.Id == id); if (shopMobiles == null) { return(null); } return(new ShopMobilesM() { Id = shopMobiles.Id, MobileId = shopMobiles.MobileId ?? -1, MobilesLeft = shopMobiles.MobilesLeft ?? 0, ShopId = shopMobiles.ShopId ?? -1, Price = shopMobiles.Price ?? 0, }); }