public void DeactiveOrder(OrderPrimitive orderPrimitive) { try { using (SmartWorkingEntities context = new SmartWorkingEntities()) { Order order = orderPrimitive.GetEntity(); Order existingObject = context.Orders.Where(x => x.Id == order.Id).FirstOrDefault(); //no record of this item in the DB, item being passed in has a PK if (existingObject == null) { throw new Exception("Only exists delivery note can be canceled."); } order.Deactivated = DateTime.Now; context.Orders.ApplyCurrentValues(order); context.SaveChanges(); } } catch (Exception e) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message); } }
public void CreateOrUpdateOrder(OrderPrimitive orderPrimitive) { try { using (SmartWorkingEntities context = new SmartWorkingEntities()) { Order order = orderPrimitive.GetEntity(); Order existingObject = context.Orders.Where(x => x.Id == order.Id).FirstOrDefault(); //no record of this item in the DB, item being passed in has a PK if (existingObject == null && order.Id > 0) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(new Exception("Błąd zapisu do bazy")), "Obiekt nie istniał w bazie, a jego Id jest większe od 0."); } //Item has no PK value, must be new); if (order.Id <= 0) { order.DateOfOrder = DateTime.Now; context.Orders.AddObject(order); } //Item was retrieved, and the item passed has a valid ID, do an update else { context.Orders.ApplyCurrentValues(order); } context.SaveChanges(); } } catch (Exception e) { throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message); } }
public static OrderPrimitive GetPrimitive(this Order entity) { OrderPrimitive primitive = new OrderPrimitive(); primitive.Id = entity.Id; primitive.Recipe_Id = entity.Recipe_Id; primitive.ClientBuilding_Id = entity.ClientBuilding_Id; primitive.Amount = entity.Amount; primitive.DateOfOrder = entity.DateOfOrder; primitive.Deleted = entity.Deleted; primitive.Deactivated = entity.Deactivated; primitive.Canceled = entity.Canceled; primitive.Pump = entity.Pump; primitive.Notice = entity.Notice; primitive.PlannedDeliveryTime = entity.PlannedDeliveryTime; return primitive; }
public static OrderPrimitive GetPrimitiveCopy(this OrderPrimitive primitiveToCopy) { if (primitiveToCopy == null) return null; OrderPrimitive primitive = new OrderPrimitive(); primitive.Id = primitiveToCopy.Id; primitive.Recipe_Id = primitiveToCopy.Recipe_Id; primitive.ClientBuilding_Id = primitiveToCopy.ClientBuilding_Id; primitive.Amount = primitiveToCopy.Amount; primitive.DateOfOrder = primitiveToCopy.DateOfOrder; primitive.Deleted = primitiveToCopy.Deleted; primitive.Deactivated = primitiveToCopy.Deactivated; primitive.Canceled = primitiveToCopy.Canceled; primitive.Pump = primitiveToCopy.Pump; primitive.Notice = primitiveToCopy.Notice; primitive.PlannedDeliveryTime = primitiveToCopy.PlannedDeliveryTime; return primitive; }
public void DeleteOrder(OrderPrimitive recipe) { throw new NotImplementedException(); }
public void UndeleteOrder(OrderPrimitive car) { throw new NotImplementedException(); }