public ShoppingM Save(ShoppingM shopping) { Shopping shoppingDb = new Shopping() { CustomerId = shopping.CustomerId, MobileId = shopping.MobileId, Price = shopping.Price, ShopId = shopping.ShopId, ShoppingStatus = shopping.Status, PurchasingDate = DateTime.Now, }; Context.Shoppings.Add(shoppingDb); Context.SaveChanges(); shopping.Id = shoppingDb.Id; return(shopping); }
public ShoppingM Delete(int id) { Shopping shopping = Context.Shoppings.SingleOrDefault(x => x.Id == id); Context.Shoppings.Remove(shopping); Context.SaveChanges(); return(new ShoppingM() { Id = shopping.Id, CustomerId = shopping.CustomerId ?? -1, MobileId = shopping.MobileId ?? -1, Price = shopping.Price ?? 0, ShopId = shopping.ShopId ?? -1, Status = shopping.ShoppingStatus, Date = shopping.PurchasingDate ?? DateTime.Now, }); }
public ShoppingM FindById(int id) { Shopping shopping = Context.Shoppings.SingleOrDefault(x => x.Id == id); if (shopping == null) { return(null); } return(new ShoppingM() { Id = shopping.Id, CustomerId = shopping.CustomerId ?? -1, MobileId = shopping.MobileId ?? -1, Price = shopping.Price ?? 0, ShopId = shopping.ShopId ?? -1, Status = shopping.ShoppingStatus, Date = shopping.PurchasingDate ?? DateTime.Now, }); }