private int SaveDispatchInformationDetails(DispatchModel model, long dispatchId, long inventoryMasterId) { int i = 0; int n = 0; foreach (var item in model.ScannedProducts) { CommandObj.Parameters.Clear(); CommandObj.CommandText = "UDSP_SaveDispatchInformationDetails"; CommandObj.CommandType = CommandType.StoredProcedure; CommandObj.Parameters.AddWithValue("@ProductId", Convert.ToInt32(item.ProductCode.Substring(2, 3))); CommandObj.Parameters.AddWithValue("@DispatchId", dispatchId); CommandObj.Parameters.AddWithValue("@ProductBarCode", item.ProductCode); CommandObj.Parameters.AddWithValue("@FactoryInventoryMasterId", inventoryMasterId); CommandObj.Parameters.AddWithValue("@TransactionRef", model.DispatchRef); CommandObj.Parameters.Add("@RowAffected", SqlDbType.Int); CommandObj.Parameters["@RowAffected"].Direction = ParameterDirection.Output; CommandObj.ExecuteNonQuery(); i += Convert.ToInt32(CommandObj.Parameters["@RowAffected"].Value); } if (i > 0) { n = SaveDispatchItems(model, dispatchId, inventoryMasterId); } return(n); }
public ActionResult _DispatchPartial(string ginNo, int type) { var commodities = _commodityService.GetAllCommodity(); var transporters = _transporterService.GetAllTransporter(); var units = _unitService.GetAllUnit(); var fdps = _fdpService.GetAllFDP(); var programs = _programService.GetAllProgram(); var regions = _adminUnitService.GetRegions(); var zones = _adminUnitService.GetAllAdminUnit().Where(t => t.AdminUnitTypeID == 2).ToList(); var stores = _storeService.GetAllStore(); ViewBag.Units = _unitService.GetAllUnit(); var dispatch = _dispatchService.GetDispatchByGIN(ginNo); var user = _userProfileService.GetUser(User.Identity.Name); if (dispatch != null) { type = dispatch.Type;//override the type by the data type coming from the DB(i.e. load the DB data by overriding the type) if (user.DefaultHub != null && user.DefaultHub.HubID == dispatch.HubID) { PrepareEdit(dispatch, user, type); var transaction = _dispatchService.GetDispatchTransaction(dispatch.DispatchID); return(PartialView("DispatchPartial", DispatchModel.GenerateDispatchModel(dispatch, transaction, commodities, transporters, units, fdps, programs, regions, zones, stores))); } PrepareCreate(type); ViewBag.Message = "The selected GIN Number doesn't exist on your default warehouse. Try changing your default warehouse."; return(PartialView("DispatchPartial", new DispatchModel(commodities, transporters, units, fdps, programs, regions, zones, stores))); } PrepareCreate(type); return(PartialView("DispatchPartial", new DispatchModel(commodities, transporters, units, fdps, programs, regions, zones, stores))); }
public static CheckResult ValidateSave(DSModel db, DispatchModel model) { CheckResult res = new CheckResult(model); if (model.DriverID == 0) { res.AddError("Please choose a Driver!", model.GetName(p => p.DriverID)); } if (model.CompanyID == 0) { res.AddError("Please choose a Company!", model.GetName(p => p.CompanyID)); } if (model.LocationID == 0) { res.AddError("Please choose a Location!", model.GetName(p => p.LocationID)); } if (model.ToDateTime < model.FromDateTime) { res.AddError("End Date Time cannot be earlier than Start Date Time!", model.GetName(p => p.ToDateTime)); } if (model.TrainingTime < 0.0m) { res.AddError("Training time cannot be negative!", model.GetName(p => p.TrainingTime)); } if (model.MiscCharge < 0m) { res.AddError("Per diem cannot be negative!", model.GetName(p => p.MiscCharge)); } var checkLicense = db.DriversLicenses .Where(d => d.DriverID == model.DriverID && d.IssueDate <= model.FromDateTime.Date && d.ExpirationDate >= model.ToDateTime) .Count(); if (checkLicense == 0) { res.AddError("Driver has no valid license for the specified dispatch dates!", model.GetName(p => p.DriverID)); } //overlap check var check = db.Dispatches .Where(d => d.DispatchID != model.DispatchID && d.DriverID == model.DriverID && d.FromDateTime <model.ToDateTime && d.ToDateTime> model.FromDateTime) .FirstOrDefault(); if (check != null) { res.AddError(string.Format("This driver has overlapping dispatches!\r\n\r\nCompany: {0}\r\nLocation: {1}\r\nStart: {2}\r\nEnd: {3}", check.Company.CompanyName, check.Location.LocationName, check.FromDateTime.ToString("g"), check.ToDateTime.ToString("g")), model.GetName(p => p.FromDateTime)); } return(res); }
public long Update(DispatchModel model) { TblDispatch obj = _mapper.Map <DispatchModel, TblDispatch>(model); List <TblDispatchDetail> dispatchDetailModel = _repositoryDetail.GetAll().Where(m => m.DispatchId == obj.DispatchId).ToList(); List <long> originalSlittingId = dispatchDetailModel.Select(m => m.SlittingId).ToList(); List <long> currentSlitingId = model.checkedSlittingId.Split(',').Select(long.Parse).ToList(); List <long> deleteSlittingId = originalSlittingId.Except(currentSlitingId).ToList(); List <long> insertSlittingId = currentSlitingId.Except(originalSlittingId).ToList(); foreach (long deleteId in deleteSlittingId) { TblDispatchDetail objModel = dispatchDetailModel.FirstOrDefault(m => m.SlittingId == deleteId); if (objModel != null) { _repositoryDetail.Delete(objModel.DispatchDetailId); } } foreach (long insertingId in insertSlittingId) { TblDispatchDetail objInsertModel = new TblDispatchDetail { DispatchId = obj.DispatchId, SlittingId = insertingId }; _repositoryDetail.Insert(objInsertModel); } _repository.Update(obj); return(obj.DispatchId); }
public long Insert(DispatchModel model) { TblDispatch obj = _mapper.Map <DispatchModel, TblDispatch>(model); obj.IsInvoiceGenerated = false; obj.IsFinalize = false; obj.Day = model.DispatchDate.Day; obj.Month = model.DispatchDate.Month; obj.Year = model.DispatchDate.Year; obj.DispatchNo = ""; obj.SequenceNo = 0; List <long> slittingIdList = model.checkedSlittingId.Split(',').Select(long.Parse).ToList(); foreach (long slittingId in slittingIdList) { obj.TblDispatchDetail.Add(new TblDispatchDetail { SlittingId = slittingId }); } _repository.Insert(obj); return(obj.DispatchId); }
public static void SaveDispatch(DSModel db, KeyBinder key, DispatchModel disp) { if (db == null) { throw new ArgumentNullException("db"); } if (key == null) { throw new ArgumentNullException("key"); } if (disp == null) { throw new ArgumentNullException("disp"); } disp.UserID = GLOB.User.UserID; disp.LastUpdateTime = DateTime.Now; if (disp.DispatchID == 0) { InsertDispatch(db, key, disp); } else { UpdateDispatch(db, key, disp); } }
private static void UpdateDispatch(DSModel db, KeyBinder key, DispatchModel model) { var poco = db.Dispatches.Where(d => d.DispatchID == model.DispatchID).FirstOrDefault(); if (poco == null) { throw new ArgumentNullException("No dispatch with the specified ID!"); } poco.DriverID = model.DriverID; poco.CompanyID = model.CompanyID; poco.LocationID = model.LocationID; poco.FromDateTime = model.FromDateTime; poco.ToDateTime = model.ToDateTime; poco.LunchTime = model.LunchTime; poco.TrainingTime = model.TrainingTime; poco.SpecialPayRate = model.SpecialPayRate; poco.MiscCharge = model.MiscCharge; poco.Note = model.Note; poco.IsCancelled = model.IsCancelled; poco.IsConfirmed = model.IsConfirmed; poco.HasLunch = model.HasLunch; poco.HasTraining = model.HasTraining; poco.UserID = model.UserID; poco.LastUpdateTime = model.LastUpdateTime; }
private void btnNewDispatch_Click(object sender, EventArgs e) { DispatchModel disp = new DispatchModel(); if (this.Dispatch != null) { disp = this.Dispatch.NewCopy(); } disp.FromDateTime = DateTime.Now.Date.AddHours(9); disp.ToDateTime = disp.FromDateTime.AddHours(8); disp.CompanyID = 0; disp.LocationID = 0; var manager = DispatchManager.Create(disp); using (XF_DispatchNewEdit form = new XF_DispatchNewEdit(manager)) { var result = form.ShowDialog(); if (result == DialogResult.Yes) { this.LoadDispatch(manager.ActiveModel); } if (DispatchChanged != null) { DispatchChanged(this, new DispatchEventArgs(this.Dispatch, result)); } } }
public ViewDispatchChalan GetDispatchChalanByDispatchId(long dispatchId) { List <ViewProduct> products = _iFactoryDeliveryGateway.GetDespatchedBarcodeByDespatchId(dispatchId).ToList(); var destination = ""; DispatchModel dispatch = GetDispatchByDispatchId(dispatchId); var viewTrip = _inventoryGateway.GetAllTrip().ToList().Find(n => n.TripId == dispatch.TripId); var details = GetDispatchDetailsByDispatchId(dispatchId); foreach (var model in details.ToList().OrderByDescending(n => n.ToBranchId).DistinctBy(n => n.ToBranchId)) { var b = _iBranchGateway.GetById(model.ToBranchId); destination += b.BranchName + "-" + b.BranchAddress + ","; } destination = destination.TrimEnd(','); var chalan = new ViewDispatchChalan { DispatchModel = dispatch, DispatchDetails = details, Destination = destination, ViewTripModel = viewTrip, Products = products }; return(chalan); }
//TODO remove this function later private void InsertDispatch(DispatchModel dispatchModel, UserProfile user) { List <DispatchDetailModel> commodities = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities); dispatchModel.DispatchDetails = commodities; _transactionService.SaveDispatchTransaction(dispatchModel, user); }
public int SaveDispatchInformation(DispatchModel dispatchModel) { ConnectionObj.Open(); SqlTransaction sqlTransaction = ConnectionObj.BeginTransaction(); try { CommandObj.Parameters.Clear(); CommandObj.Transaction = sqlTransaction; CommandObj.CommandText = "UDSP_SaveDispatchInformation"; CommandObj.CommandType = CommandType.StoredProcedure; CommandObj.Parameters.AddWithValue("@DispatchDate", dispatchModel.DispatchDate); CommandObj.Parameters.AddWithValue("@TripId", dispatchModel.TripModel.TripId); CommandObj.Parameters.AddWithValue("@TripStatus", dispatchModel.TripModel.Status); //CommandObj.Parameters.AddWithValue("@RequisitionId", dispatchModel.TripModel.RequisitionId); //CommandObj.Parameters.AddWithValue("@ToBranchId", dispatchModel.TripModel.ToBranchId); //CommandObj.Parameters.AddWithValue("@ProductId", dispatchModel.TripModel.ProuctId); CommandObj.Parameters.AddWithValue("@TransactionRef", dispatchModel.TripModel.TripRef); CommandObj.Parameters.AddWithValue("@Quantity", dispatchModel.ScannedProducts.ToList().Count); CommandObj.Parameters.AddWithValue("@DispatchRef", dispatchModel.DispatchRef); CommandObj.Parameters.AddWithValue("@CompanyId", dispatchModel.CompanyId); CommandObj.Parameters.AddWithValue("@DispatchByUserId", dispatchModel.DispatchByUserId); CommandObj.Parameters.Add("@DispatchId", SqlDbType.BigInt); CommandObj.Parameters["@DispatchId"].Direction = ParameterDirection.Output; CommandObj.Parameters.Add("@InventoryMasterId", SqlDbType.BigInt); CommandObj.Parameters["@InventoryMasterId"].Direction = ParameterDirection.Output; CommandObj.ExecuteNonQuery(); long dispatchId = Convert.ToInt64(CommandObj.Parameters["@DispatchId"].Value); long inventoryMasterId = Convert.ToInt64(CommandObj.Parameters["@InventoryMasterId"].Value); int rowAffected = SaveDispatchInformationDetails(dispatchModel, dispatchId, inventoryMasterId); if (rowAffected > 0) { sqlTransaction.Commit(); } else { sqlTransaction.Rollback(); } return(rowAffected); } catch (Exception exception) { Log.WriteErrorLog(exception); sqlTransaction.Rollback(); throw new Exception("Could not Save dispatch Info", exception); } finally { ConnectionObj.Close(); CommandObj.Dispose(); CommandObj.Parameters.Clear(); } }
public void ClearDispatch() { this.Dispatch = null; DriverID.DataBindings.Clear(); DriverID.DriverID = 0; CompanyID.DataBindings.Clear(); CompanyID.CompanyID = 0; TotalTime.EditValue = null; OverTime.EditValue = null; }
public ActionResult SaveDispatchInformation(long tripId) { try { var user = (ViewUser)Session["user"]; string fileName = "Deliverable_Product_For_" + user.UserId + "_" + tripId; var filePath = Server.MapPath("~/Files/" + fileName); var scannedProducts = _iProductManager.GetScannedProductListFromTextFile(filePath).ToList(); if (scannedProducts.Count > 0) { var products = _iProductManager.GetDeliverableProductListByTripId(tripId); int dispatchByUserId = ((ViewUser)Session["user"]).UserId; int companyId = Convert.ToInt32(Session["CompanyId"]); var viewTrip = _iInventoryManager.GetAllTrip().ToList().Find(n => n.TripId == tripId); viewTrip.Status = 2; var tripQty = products.Sum(n => n.Quantity); var deliveryQty = scannedProducts.Count; if (tripQty != deliveryQty) { viewTrip.Status = 1; } DispatchModel model = new DispatchModel { DispatchByUserId = dispatchByUserId, CompanyId = companyId, TripModel = viewTrip, DispatchDate = DateTime.Now, ScannedProducts = scannedProducts, DispatchModels = products }; string result = _iFactoryDeliveryManager.SaveDispatchInformation(model); if (result.StartsWith("Sa")) { System.IO.File.Create(filePath).Close(); //---------------Send mail to branch before redirect-------------- TempData["Dispatched"] = result; return(RedirectToAction("DeliverableTransferIssueList")); } return(RedirectToAction("Delivery", new { id = tripId })); } return(RedirectToAction("Delivery", new { id = tripId })); } catch (Exception exception) { Log.WriteErrorLog(exception); return(PartialView("_ErrorPartial", exception)); } }
// // GET: /Dispatch/Details/5 public ActionResult Details(int id) { DispatchModel dispatch = DispatchDAO.GetDispatchByID(id); if (dispatch != null) { return(View(dispatch)); } else { return(RedirectToAction("index")); } }
public string SaveDispatchInformation(DispatchModel dispatchModel) { int maxDispatchNo = _inventoryGateway.GetMaxDispatchRefNoOfCurrentYear(); dispatchModel.DispatchRef = GenerateDispatchReference(maxDispatchNo); int rowAffected = _iFactoryDeliveryGateway.SaveDispatchInformation(dispatchModel); if (rowAffected > 0) { return("Saved Successfully!"); } return("Failed to Save"); }
public ActionResult Create(FormCollection collection) { try { DispatchModel form = new DispatchModel(); TryUpdateModel <DispatchModel>(form, collection.ToValueProvider()); int rowsAffected = DispatchDAO.Insert(form); return(RedirectToAction("Index")); } catch { return(RedirectToAction("Create")); } }
public IActionResult SaveDispatch(DispatchModel model, string create) { if (!ModelState.IsValid) { return(View("CreateDispatch", model)); } string message = string.Empty; long id = 0; try { if (create == "Finalize Dispatch") { model.IsFinalize = true; id = _service.Update(model); } else if (model.DispatchId > 0) { id = _service.Update(model); } else { id = _service.Insert(model); } } catch (Exception ex) { message = CommonHelper.GetErrorMessage(ex); } if (!string.IsNullOrEmpty(message)) { ViewBag.openPopup = CommonHelper.ShowAlertMessage(message); return(View("CreateDispatch", model)); } if (create == "Save & Continue") { return(RedirectToAction("Edit", "Dispatch", new { id })); } return(RedirectToAction("Index")); }
public static void DeleteDispatch(DSModel db, DispatchModel disp) { if (db == null) { throw new ArgumentNullException("db"); } if (disp == null) { throw new ArgumentNullException("disp"); } if (disp.DispatchID != 0) { var poco = db.Dispatches.Where(d => d.DispatchID == disp.DispatchID).FirstOrDefault(); if (poco != null) { db.Delete(poco); } } }
public CheckResult DeleteDispatch(DispatchModel model) { try { using (var db = DB.GetContext()) { var check = DispatchValidator.ValidateDelete(db, model); if (check.Failed) return check; DispatchRepository.DeleteDispatch(db, model); db.SaveChanges(); return check; } } catch (Exception ex) { return new CheckResult(ex); } }
public DispatchModel GetDispatchByDispatchId(long dispatchId) { try { CommandObj.CommandText = "UDSP_GetDispatchByDispatchId"; CommandObj.CommandType = CommandType.StoredProcedure; CommandObj.Parameters.AddWithValue("@DispatchId", dispatchId); DispatchModel dispatch = null; ConnectionObj.Open(); SqlDataReader reader = CommandObj.ExecuteReader(); if (reader.Read()) { dispatch = new DispatchModel { DispatchId = dispatchId, CompanyId = Convert.ToInt32(reader["CompanyId"]), TransactionRef = reader["TransactionRef"].ToString(), TripId = Convert.ToInt64(reader["TripId"]), DispatchByUserId = Convert.ToInt32(reader["DispatchByUserId"]), DispatchDate = Convert.ToDateTime(reader["DispatchDate"]), SystemDateTime = Convert.ToDateTime(reader["SystemDateTime"]), DispatchRef = reader["DispatchRef"].ToString(), IsCanclled = reader["IsCancelled"].ToString(), Quantity = Convert.ToInt32(reader["Quantity"]), Remarks = DBNull.Value.Equals(reader["Remarks"])?null:reader["Remarks"].ToString() }; } reader.Close(); return(dispatch); } catch (Exception exception) { throw new Exception("Could not get dispatch Info by dispatchId", exception); } finally { ConnectionObj.Close(); CommandObj.Dispose(); CommandObj.Parameters.Clear(); } }
public void LoadDispatch(DispatchModel disp) { this.Dispatch = disp; BindingSource bsDisp = new BindingSource(); bsDisp.DataSource = disp; DriverID.DataBindings.Clear(); DriverID.DataBindings.Add("DriverID", bsDisp, disp.GetName(p => p.DriverID), true, DataSourceUpdateMode.OnPropertyChanged); CompanyID.DataBindings.Clear(); CompanyID.DataBindings.Add("CompanyID", bsDisp, disp.GetName(p => p.CompanyID), true, DataSourceUpdateMode.OnPropertyChanged); double totalTime = (disp.ToDateTime - disp.FromDateTime).TotalHours; totalTime = totalTime - (disp.LunchTime / 60.0d); double overTime = (totalTime > 8.0d ? totalTime - 8.0d : 0.0d); TotalTime.EditValue = totalTime; OverTime.EditValue = overTime; }
public CheckResult DeleteDispatch(DispatchModel model) { try { using (var db = DB.GetContext()) { var check = DispatchValidator.ValidateDelete(db, model); if (check.Failed) { return(check); } DispatchRepository.DeleteDispatch(db, model); db.SaveChanges(); return(check); } } catch (Exception ex) { return(new CheckResult(ex)); } }
public CheckResult SaveDispatch(DispatchModel model) { try { using (var db = DB.GetContext()) { var check = DispatchValidator.ValidateSave(db, model); if (check.Failed) return check; KeyBinder key = new KeyBinder(); DispatchRepository.SaveDispatch(db, key, model); db.SaveChanges(); key.BindKeys(); return check; } } catch (Exception ex) { return new CheckResult(ex); } }
public ActionResult _DispatchPartial(string ginNo, int type) { ViewBag.Units = _unitService.GetAllUnit(); var dispatch = _dispatchService.GetDispatchByGIN(ginNo); var user = _userProfileService.GetUser(User.Identity.Name); if (dispatch != null) { type = dispatch.Type;//override the type by the data type coming from the DB(i.e. load the DB data by overriding the type) if (user.DefaultHub != null && user.DefaultHub.HubID == dispatch.HubID) { PrepareEdit(dispatch, user, type); var transaction = _dispatchService.GetDispatchTransaction(dispatch.DispatchID); return(PartialView("DispatchPartial", DispatchModel.GenerateDispatchModel(dispatch, transaction))); } PrepareCreate(type); ViewBag.Message = "The selected GIN Number doesn't exist on your default warehouse. Try changing your default warehouse."; return(PartialView("DispatchPartial", new DispatchModel())); } PrepareCreate(type); return(PartialView("DispatchPartial", new DispatchModel())); }
private int SaveDispatchItems(DispatchModel model, long dispatchId, long inventoryMasterId) { int i = 0; var scannProducts = model.ScannedProducts; foreach (var item in model.DispatchModels) { var qty = scannProducts.Count(n => n.ProductId.Equals(item.ProductId)); CommandObj.Parameters.Clear(); CommandObj.CommandText = "UDSP_SaveDispatchItems"; CommandObj.CommandType = CommandType.StoredProcedure; CommandObj.Parameters.AddWithValue("@ProductId", item.ProductId); CommandObj.Parameters.AddWithValue("@Quantity", qty); CommandObj.Parameters.AddWithValue("@ToBranchId", item.ToBranchId); CommandObj.Parameters.AddWithValue("@DispatchId", dispatchId); CommandObj.Parameters.AddWithValue("@InventoryMasterId", inventoryMasterId); CommandObj.Parameters.Add("@RowAffected", SqlDbType.Int); CommandObj.Parameters["@RowAffected"].Direction = ParameterDirection.Output; CommandObj.ExecuteNonQuery(); i += Convert.ToInt32(CommandObj.Parameters["@RowAffected"].Value); } return(i); }
private static void InsertDispatch(DSModel db, KeyBinder key, DispatchModel model) { Dispatch poco = new Dispatch(); poco.DriverID = model.DriverID; poco.CompanyID = model.CompanyID; poco.LocationID = model.LocationID; poco.FromDateTime = model.FromDateTime; poco.ToDateTime = model.ToDateTime; poco.LunchTime = model.LunchTime; poco.TrainingTime = model.TrainingTime; poco.SpecialPayRate = model.SpecialPayRate; poco.MiscCharge = model.MiscCharge; poco.Note = model.Note; poco.IsCancelled = model.IsCancelled; poco.IsConfirmed = model.IsConfirmed; poco.HasLunch = model.HasLunch; poco.HasTraining = model.HasTraining; poco.UserID = model.UserID; poco.LastUpdateTime = model.LastUpdateTime; db.Add(poco); key.AddKey(poco, model, model.GetName(p => p.DispatchID)); }
private void BindModel(DispatchModel model) { BindingSource bsMod = new BindingSource(); bsMod.DataSource = model; DriverID.DataBindings.Add("DriverID", bsMod, model.GetName(p => p.DriverID), true, DataSourceUpdateMode.OnPropertyChanged); CompanyID.DataBindings.Add("CompanyID", bsMod, model.GetName(p => p.CompanyID), true, DataSourceUpdateMode.OnPropertyChanged); LocationID.DataBindings.Add("LocationID", bsMod, model.GetName(p => p.LocationID), true, DataSourceUpdateMode.OnPropertyChanged); FromDateTime.DataBindings.Add("EditValue", bsMod, model.GetName(p => p.FromDateTime), true, DataSourceUpdateMode.OnPropertyChanged); ToDateTime.DataBindings.Add("EditValue", bsMod, model.GetName(p => p.ToDateTime), true, DataSourceUpdateMode.OnPropertyChanged); SpecialPayRate.DataBindings.Add("EditValue", bsMod, model.GetName(p => p.SpecialPayRate), true, DataSourceUpdateMode.OnPropertyChanged); MiscCharge.DataBindings.Add("EditValue", bsMod, model.GetName(p => p.MiscCharge), true, DataSourceUpdateMode.OnPropertyChanged); IsCancelled.DataBindings.Add("Checked", bsMod, model.GetName(p => p.IsCancelled), true, DataSourceUpdateMode.OnPropertyChanged); HasLunch.DataBindings.Add("Checked", bsMod, model.GetName(p => p.HasLunch), true, DataSourceUpdateMode.OnPropertyChanged); HasTraining.DataBindings.Add("Checked", bsMod, model.GetName(p => p.HasTraining), true, DataSourceUpdateMode.OnPropertyChanged); CancelledHours.DataBindings.Add("EditValue", bsMod, model.GetName(p => p.CancelledHours), true, DataSourceUpdateMode.OnPropertyChanged); Note.DataBindings.Add("EditValue", bsMod, model.GetName(p => p.Note), true, DataSourceUpdateMode.OnPropertyChanged); LastEdit.Text = model.UserName + " on " + model.LastUpdateTime.ToString(GLOB.Formats.DateTime); LocationID.Tag = model; }
public ActionResult Edit(int id, FormCollection collection) { DispatchModel form = new DispatchModel(); try { TryUpdateModel <DispatchModel>(form, collection.ToValueProvider()); int rowsAffected = DispatchDAO.UpdateForm(form); } catch { return(View()); } try { return(RedirectToAction("Edit", new { id = form.FormID })); } catch { return(RedirectToAction("Index")); } }
public virtual ActionResult Edit(int?dispatchID) { try { TempData["sDispatch"] = from x in PaymentsMethodsExtensions.typedispatchDisplay() orderby x.Key select new SelectListItem() { Text = x.Value, Value = x.Key }; DispatchTable dispatch = new DispatchTable(); dispatch = Dispatch.DispatchById(Convert.ToInt32(dispatchID)); dispatch.ProductsQuery = DispatchItems.DispatchItemsByDispatchID(Convert.ToInt32(dispatchID)); DispatchModel model = new DispatchModel(dispatch); return(View(model)); } catch (Exception ex) { var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException); throw exception; } }
public CheckResult SaveDispatch(DispatchModel model) { try { using (var db = DB.GetContext()) { var check = DispatchValidator.ValidateSave(db, model); if (check.Failed) { return(check); } KeyBinder key = new KeyBinder(); DispatchRepository.SaveDispatch(db, key, model); db.SaveChanges(); key.BindKeys(); return(check); } } catch (Exception ex) { return(new CheckResult(ex)); } }
public static DispatchManager Create(DispatchModel model) { return new DispatchManager(model); }
public ActionResult Create(DispatchModel dispatchModel) { var user = _userProfileService.GetUser(User.Identity.Name); var insertCommodities = new List <DispatchDetailModel>(); var updateCommodities = new List <DispatchDetailModel>(); var prevCommodities = new List <DispatchDetailModel>(); if (dispatchModel.JSONPrev != null) { prevCommodities = GetSelectedCommodities(dispatchModel.JSONPrev); //Even though they are updated they are not saved so move them in to the inserted at the end of a succcessful submit int count = 0; foreach (var dispatchDetailAllViewModels in prevCommodities) { if (dispatchDetailAllViewModels.Id != null) { count--; dispatchDetailAllViewModels.DispatchDetailCounter = count; insertCommodities.Add(dispatchDetailAllViewModels); } else { updateCommodities.Add(dispatchDetailAllViewModels); } } ViewBag.ReceiveDetails = prevCommodities; ViewBag.SelectedCommodities = prevCommodities; dispatchModel.DispatchDetails = prevCommodities; //this check need's to be revisited if (!prevCommodities.Any()) { ModelState.AddModelError("DispatchDetails", @"Please add atleast one commodity to save this Dispatch"); } string errorMessage = null; foreach (var dispatchDetailViewModel in prevCommodities) { var validationContext = new ValidationContext(dispatchDetailViewModel, null, null); var validationResults = dispatchDetailViewModel.Validate(validationContext); errorMessage = validationResults.Aggregate(errorMessage, (current, v) => string.Format("{0}, {1}", current, v.ErrorMessage)); var comms = _commodityService.FindById(dispatchDetailViewModel.CommodityID); var commType = _commodityTypeService.FindById(dispatchModel.CommodityTypeID); if (dispatchModel.CommodityTypeID != comms.CommodityTypeID) { ModelState.AddModelError("DispatchDetails", comms.Name + @" is not of type " + commType.Name); } } if (errorMessage != null) { ModelState.AddModelError("DispatchDetails", errorMessage); } } else { ModelState.AddModelError("DispatchDetails", @"Please add atleast one commodity to save this Dispatch"); } if (dispatchModel.Type != 1) { ModelState.Remove("FDPID"); ModelState.Remove("RegionID"); ModelState.Remove("WoredaID"); ModelState.Remove("ZoneID"); ModelState.Remove("BidNumber"); dispatchModel.BidNumber = "00000"; //NOT really needed ModelState.Remove("Year"); ModelState.Remove("Month"); } else { ModelState.Remove("ToHubID"); } if (ModelState.IsValid && user != null) { if (dispatchModel.ChangeStoreManPermanently) { var storeTobeChanged = _storeService.FindById(dispatchModel.StoreID); if (storeTobeChanged != null && dispatchModel.ChangeStoreManPermanently) { storeTobeChanged.StoreManName = dispatchModel.DispatchedByStoreMan; } } var dispatch = dispatchModel.GenerateDipatch(user); //if (dispatch.DispatchID == null ) if (dispatchModel.DispatchID == null) { dispatchModel.DispatchDetails = prevCommodities; foreach (var gridCommodities in prevCommodities) { if (user.PreferedWeightMeasurment.Equals("qn")) { gridCommodities.DispatchedQuantityMT /= 10; gridCommodities.RequestedQuantityMT /= 10; } } //InsertDispatch(dispatchModel, user); _transactionService.SaveDispatchTransaction(dispatchModel, user); } else { // List<Models.DispatchDetailModel> insertCommodities = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities); var deletedCommodities = GetSelectedCommodities(dispatchModel.JSONDeletedCommodities); // List<Models.DispatchDetailModel> updateCommodities = GetSelectedCommodities(dispatchModel.JSONUpdatedCommodities); dispatch.HubID = user.DefaultHub.HubID; dispatch.Update(GenerateDispatchDetail(insertCommodities), GenerateDispatchDetail(updateCommodities), GenerateDispatchDetail(deletedCommodities)); } return(RedirectToAction("Index")); } //List<Models.DispatchDetailModel> details = GetSelectedCommodities(dispatchModel.JSONInsertedCommodities); //Session["SELCOM"] = details; // BLL.UserProfile user = BLL.UserProfile.GetUser(User.Identity.Name); PrepareCreate(dispatchModel.Type); if (dispatchModel.FDPID != null) { PrepareFDPForEdit(dispatchModel.FDPID); dispatchModel.WoredaID = _fdpService.FindById(dispatchModel.FDPID.Value).AdminUnitID; } //PrepareEdit(dispatchModel.GenerateDipatch(), user,dispatchModel.Type); return(View(dispatchModel)); }
public static void SaveDispatch(DSModel db, KeyBinder key, DispatchModel disp) { if (db == null) throw new ArgumentNullException("db"); if (key == null) throw new ArgumentNullException("key"); if (disp == null) throw new ArgumentNullException("disp"); disp.UserID = GLOB.User.UserID; disp.LastUpdateTime = DateTime.Now; if (disp.DispatchID == 0) InsertDispatch(db, key, disp); else UpdateDispatch(db, key, disp); }
private DispatchManager(DispatchModel model) { this.ActiveModel = model; }
private static void UpdateDispatch(DSModel db, KeyBinder key, DispatchModel model) { var poco = db.Dispatches.Where(d => d.DispatchID == model.DispatchID).FirstOrDefault(); if (poco == null) throw new ArgumentNullException("No dispatch with the specified ID!"); poco.DriverID = model.DriverID; poco.CompanyID = model.CompanyID; poco.LocationID = model.LocationID; poco.FromDateTime = model.FromDateTime; poco.ToDateTime = model.ToDateTime; poco.LunchTime = model.LunchTime; poco.TrainingTime = model.TrainingTime; poco.SpecialPayRate = model.SpecialPayRate; poco.MiscCharge = model.MiscCharge; poco.Note = model.Note; poco.IsCancelled = model.IsCancelled; poco.IsConfirmed = model.IsConfirmed; poco.HasLunch = model.HasLunch; poco.HasTraining = model.HasTraining; poco.UserID = model.UserID; poco.LastUpdateTime = model.LastUpdateTime; }
public static void DeleteDispatch(DSModel db, DispatchModel disp) { if (db == null) throw new ArgumentNullException("db"); if (disp == null) throw new ArgumentNullException("disp"); if (disp.DispatchID != 0) { var poco = db.Dispatches.Where(d => d.DispatchID == disp.DispatchID).FirstOrDefault(); if (poco != null) db.Delete(poco); } }
public DispatchEventArgs(DispatchModel disp, DialogResult result) { this.Dispatch = disp; this.DialogResult = result; }