public ActionResult Create(TruckLoadModel truckLoadModel)
        {
            ModelState.Clear <TruckLoadModel>(x => x.TruckModel);
            ModelState.Clear <TruckLoadModel>(x => x.DriverModel);
            ModelState.Clear <TruckLoadModel>(x => x.CompanyModel);

            using (TruckLoadBAL truckLoadBAL = new TruckLoadBAL(ContextInfo))
            {
                if (ModelState.IsValid)
                {
                    truckLoadBAL.Create(truckLoadModel);
                }

                if (truckLoadModel.HasErrorByType(LMYFrameWorkMVC.Common.LookUps.ErrorType.Critical) || truckLoadModel.HasSuccess(LMYFrameWorkMVC.Common.LookUps.SuccessType.Full))
                {
                    return(base.RedirectToActionWithData(new Dictionary <string, object> {
                        { "baseModel", truckLoadModel }
                    }));
                }

                truckLoadBAL.PrepareTruckLoadModel(truckLoadModel);
            }

            return(View("Create", truckLoadModel));
        }
        public ActionResult Delete(TruckLoadModel truckLoadModel)
        {
            using (TruckLoadBAL truckLoadBAL = new TruckLoadBAL(ContextInfo))
            {
                truckLoadBAL.Delete(truckLoadModel);

                if (truckLoadModel.HasErrorByType())
                {
                    truckLoadBAL.GetTruckLoadModel(truckLoadModel);
                }
            }

            return(View(truckLoadModel));
        }
Esempio n. 3
0
        private bool Validate(TruckLoadModel truckLoadModel)
        {
            if (dbContext.TruckLoads.Any(x =>
                                         x.TruckId == truckLoadModel.TruckId &&
                                         x.Id != truckLoadModel.Id.ToString() &&
                                         (
                                             x.FromDate.HasValue && x.ToDate.HasValue &&
                                             truckLoadModel.FromDate.HasValue &&
                                             !(truckLoadModel.FromDate.Value > x.ToDate.Value || truckLoadModel.FromDate.Value < x.FromDate.Value)
                                         ) &&
                                         (
                                             x.FromDate.HasValue && x.ToDate.HasValue &&
                                             truckLoadModel.ToDate.HasValue &&
                                             !(truckLoadModel.ToDate.Value > x.ToDate.Value || truckLoadModel.ToDate.Value < x.FromDate.Value)
                                         )
                                         ))
            {
                base.HandleError(truckLoadModel, CommonLayer.LookUps.ErrorType.Business, null, string.Format(Resources.DurationIsOverLappedWithOtherLoad, truckLoadModel.GetDisplayName(x => x.Name)), truckLoadModel.nameof(x => x.Name));
            }

            return(truckLoadModel.HasErrorByType());
        }
Esempio n. 4
0
 private bool ValidateDelete(TruckLoadModel truckLoadModel)
 {
     return(truckLoadModel.HasErrorByType());
 }