public bool AddOrder(Order order) { try { entity.Orders.Add(order); entity.SaveChanges(); return true; } catch (Exception ex) { return false; } }
public bool UpdateOrder(Order order) { try { Order oldorder = entity.Orders.FirstOrDefault(r => r.ID == order.ID); if (oldorder != null) { oldorder.Price = order.Price; oldorder.Name = order.Name; entity.Entry(oldorder).State = System.Data.Entity.EntityState.Modified; entity.SaveChanges(); return true; } else { return false; } } catch (Exception ex) { return false; } }
public static OrderViewModel ToViewModel(Order Model) { return new OrderViewModel() { ID = Model.ID, Price = Model.Price, Name = Model.Name }; }