public void UpdateContainer(smART.ViewModel.Scale businessEntity, smART.Model.Scale modelEntity, smART.Model.smARTDBContext dbContext) { try { if (modelEntity.Ticket_Type.ToLower() == "shipping ticket") { smART.Model.Container container = dbContext.T_Container_Ref.Include("Booking").FirstOrDefault(m => m.ID == modelEntity.Container_No.ID); container.Seal1_No = modelEntity.Seal_No; container.Chasis_No = modelEntity.Trailer_Chasis_No; container.Gross_Weight = modelEntity.Gross_Weight; container.Tare_Weight = modelEntity.Tare_Weight; container.Net_Weight = modelEntity.Net_Weight; container.Status = GetContainerStatus(modelEntity, container, dbContext); dbContext.SaveChanges(); } } catch (Exception ex) { bool rethrow; rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString()); if (rethrow) { throw ex; } } }
public string GetContainerStatus(smART.Model.Scale modelEntity, smART.Model.Container container, smART.Model.smARTDBContext dbContext) { string status = string.Empty; try { Model.Booking modBooking = container.Booking; smART.Model.DispatcherRequest modDispatcher = dbContext.T_Dispatcher.FirstOrDefault(m => m.Booking_Ref_No.ID == container.Booking.ID); if (modBooking != null && modBooking.Invoice_Generated_Flag == true) { status = "Closed"; } else if (modelEntity != null && modelEntity.Ticket_Status.ToLower() == "open") { status = "WIP"; } else if (modelEntity != null && modelEntity.Ticket_Status.ToLower() == "close") { if (modDispatcher != null && modDispatcher.RequestType.ToLower() == "drop off only") { status = "Shipped"; } else if (container.Status.ToLower() == "wip" || container.Status.ToLower() == "open-empty") { status = "Open-Loaded"; } else { status = container.Status; } } else if (modDispatcher != null && modDispatcher.RequestType.ToLower() == "pickup only") { status = "Open-Empty"; } else if (modDispatcher != null && modDispatcher.RequestType.ToLower() == "drop off only") { if (modelEntity != null) { status = "Shipped"; } else { status = "Open-Empty"; } } } catch (Exception ex) { bool rethrow; rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, modelEntity.Updated_By, modelEntity.GetType().Name, modelEntity.ID.ToString()); if (rethrow) { throw ex; } } return(status); }
public void Adding(smART.ViewModel.Container businessEntity, smART.Model.Container modelEntity, smART.Model.smARTDBContext dbContext, out bool cancel) { // If Status is null or empty set default status to "Open-Loaded" if (string.IsNullOrEmpty(modelEntity.Status.Trim())) { modelEntity.Status = "Open-Loaded"; } // Set default Date_In date to current system date. modelEntity.Date_In = DateTime.Now; cancel = false; }
public void UpdateContainer(smART.ViewModel.DispatcherRequest businessEntity, smART.Model.DispatcherRequest modelEntity, smART.Model.smARTDBContext dbContext) { try { if (modelEntity.RequestCategory.ToLower() == "container" && !string.IsNullOrEmpty(businessEntity.Container_No)) { Model.Booking modBooking = dbContext.T_Booking_Ref.FirstOrDefault(o => o.ID.Equals(modelEntity.Booking_Ref_No.ID)); if (modBooking != null) { Model.Container modContainer = dbContext.T_Container_Ref.Include("Booking").FirstOrDefault(o => o.Container_No == businessEntity.Container_No && o.Active_Ind == true); if (modContainer == null) { smART.Model.Container modNewcontainer = new smART.Model.Container(); modNewcontainer.Booking = modBooking; modNewcontainer.Container_No = businessEntity.Container_No; modNewcontainer.Created_Date = modelEntity.Time; modNewcontainer.Last_Updated_Date = modelEntity.Time; modNewcontainer.Created_By = modelEntity.Created_By; modNewcontainer.Updated_By = modelEntity.Updated_By; modNewcontainer.Date_In = DateTime.Now; modNewcontainer.Status = GetContainerStatus(modBooking, modelEntity, dbContext); modNewcontainer.Active_Ind = true; Model.Container insertedObject = dbContext.T_Container_Ref.Add(modNewcontainer); modContainer = insertedObject; dbContext.SaveChanges(); modelEntity.Container = modContainer; } else { modContainer.Last_Updated_Date = DateTime.Now; modContainer.Updated_By = modelEntity.Updated_By; modelEntity.Container = modContainer; modelEntity.Booking_Ref_No = dbContext.T_Booking_Ref.FirstOrDefault(o => o.ID == modContainer.Booking.ID); modContainer.Status = GetContainerStatus(modelEntity.Booking_Ref_No, modelEntity, dbContext); dbContext.SaveChanges(); } } } } catch (Exception ex) { bool rethrow; rethrow = BusinessRuleExceptionHandler.HandleException(ref ex, businessEntity.Updated_By, businessEntity.GetType().Name, businessEntity.ID.ToString()); if (rethrow) { throw ex; } } }