public ActionResult FDP_Update(int fdpId) { var fdp = _fdpService.FindById(fdpId); var fvm = FDPViewModelBinder.BindFDPViewModel(fdp); return(View(fvm)); }
public ActionResult Create_contact(int fdpId) { var fdp = _fdpService.FindById(fdpId); var vm = new ContactViewModel(); vm.FDPName = fdp.Name; vm.FDPID = fdpId; return(View(vm)); }
private void PrepareFDPForEdit(int?fdpid) { AdminUnitModel unitModel = new AdminUnitModel(); FDP fdp; if (fdpid != null) { fdp = _fdpService.FindById(fdpid.Value); } else { fdp = null; } if (fdp != null) { unitModel.SelectedWoredaId = fdp.AdminUnitID; if (fdp.AdminUnit.ParentID != null) { unitModel.SelectedZoneId = fdp.AdminUnit.ParentID.Value; } unitModel.SelectedRegionId = _adminUnitService.GetRegionByZoneId(unitModel.SelectedZoneId); ViewBag.Regions = new SelectList( _adminUnitService.GetRegions().Select(p => new { Id = p.AdminUnitID, Name = p.Name }).OrderBy( o => o.Name), "Id", "Name", unitModel.SelectedRegionId); ViewBag.Zones = new SelectList(this.GetChildren(unitModel.SelectedRegionId).OrderBy(o => o.Name), "Id", "Name", unitModel.SelectedZoneId); ViewBag.Woredas = new SelectList(this.GetChildren(unitModel.SelectedZoneId).OrderBy(o => o.Name), "Id", "Name", unitModel.SelectedWoredaId); ViewBag.FDPS = new SelectList(this.GetFdps(unitModel.SelectedWoredaId).OrderBy(o => o.Name), "Id", "Name", fdp.FDPID); } else { ViewBag.SelectedRegionId = new SelectList(unitModel.Regions, "Id", "Name"); ViewBag.SelectedWoredaId = new SelectList(Enumerable.Empty <SelectListItem>(), "Id", "Name"); ViewBag.FDPID = new SelectList(Enumerable.Empty <SelectListItem>(), "Id", "Name"); ViewBag.SelectedZoneId = new SelectList(Enumerable.Empty <SelectListItem>(), "Id", "Name"); } }
// // GET: /Contact/ public ViewResult Index(int?fdpId) { if (fdpId.HasValue) { var contacts = _contactService.GetByFdp(fdpId.Value); ViewBag.FDPID = fdpId.Value; ViewBag.FDPName = _fdpService.FindById(fdpId.Value).Name; return(View("Index", contacts.ToList())); } else { var contacts = _contactService.GetAllContact(); return(View("Index", contacts)); } }
// // GET: /FDP/Details/5 public virtual ViewResult Details(int id) { FDP fdp = _FDPService.FindById(id); return(View(fdp)); }
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)); }