public ActionResult DeleteOrder(VmKoOrder order) { try { if (CurrentUser.UserLevel < (int)Enums.AccessLevel.Entry) { throw new ServerException("Save Order: User does not have permission to save an order"); } var dbOrder = Db.Orders.FirstOrDefault(o => o.OrderId == order.OrderId); if (dbOrder != null) { if (dbOrder.LoadId != null) { var load = Db.Loads.FirstOrDefault(l => l.LoadId == dbOrder.LoadId); if (load != null) { load.ModifiedByUserLoginId = CurrentUser.UserLoginId; load.ModifiedDate = DateTime.Now; } } Db.Orders.Remove(dbOrder); Db.SaveChanges(); } } catch (Exception e) { return(ReturnOrder(order, ServerError.GetErrorFromException(e).ExceptionMsg)); } return(ReturnOrder(order, $"Order# {order.OrderNumber} has been deleted")); }
private JsonResult ReturnOrder(VmKoOrder order, string actionMessage = "") { order.ActionResultMessage = actionMessage; var rtnOrder = Json(order.ToJsonString(), JsonRequestBehavior.AllowGet); return(rtnOrder); }
public ActionResult SaveOrder(VmKoOrder order) { try { if (CurrentUser.UserLevel < (int)Enums.AccessLevel.Entry) { throw new ServerException("Save Order: User does not have permission to save an order"); } var dbOrder = Db.Orders.FirstOrDefault(o => o.OrderId == order.OrderId); if (dbOrder != null) { var isOnLoad = dbOrder.LoadId != null; if (isOnLoad) { var dbLoad = Db.Loads.Find(dbOrder.LoadId); if (dbLoad != null) { dbLoad.ModifiedDate = DateTime.Now; dbLoad.ModifiedByUserLoginId = CurrentUser.UserLoginId; } } dbOrder.CustAddress = order.CustomerAddress; dbOrder.CustomerName = order.CustomerName; dbOrder.OrderNumber = order.OrderNumber; dbOrder.DeliveryDate = order.DeliveryDate; dbOrder.PickupDate = order.PickupDate; dbOrder.Destination = order.Destination; dbOrder.WarehouseId = order.WarehouseId; dbOrder.IsDangerousGoods = order.IsDangerousGoods; dbOrder.IsCustomerPickup = order.IsCustomerPickup; dbOrder.Notes = order.Notes; dbOrder.Volume = order.Volume; dbOrder.UnitOfMeasureId = order.UnitOfMeasureId; dbOrder.WeightKg = order.WeightKg; dbOrder.ModifiedDate = DateTime.Now; dbOrder.ModifiedByUserLoginId = CurrentUser.UserLoginId; Db.SaveChanges(); } else {// add it;) var newOrder = new Order() { OrderNumber = order.OrderNumber, CreatedDate = DateTime.Now, CreatedByUserLoginId = CurrentUser.UserLoginId }; Db.Orders.Add(newOrder); Db.SaveChanges(); order.OrderId = newOrder.OrderId; order.LastChangeDate = newOrder.CreatedDate; order.UserName = CurrentUser.DisplayName; } } catch (Exception e) { return(ReturnOrder(order, ServerError.GetErrorFromException(e).ExceptionMsg)); } return(ReturnOrder(order, $"Order# {order.OrderNumber} has been saved")); }