private void PrepareEdit(DispatchAllocationViewModel allocation)
        {
            ViewBag.Commodities = new SelectList(_commonService.GetAllParents(), "CommodityID", "Name", allocation.CommodityID);

            ViewBag.CommodityTypes = new SelectList(_commonService.GetAllCommodityType(), "CommodityTypeID", "Name",allocation.CommodityTypeID);

            ViewBag.Donors = new SelectList(_commonService.GetAllDonors(), "DonorID", "Name", allocation.DonorID);

            ViewBag.Years = new SelectList(_commonService.GetYears().Select(y => new { Name = y, Id = y }), "Id", "Name", allocation.Year);
            if (allocation.Year.HasValue)
            {
                ViewBag.Months = new SelectList(_commonService.GetMonths(allocation.Year.Value).Select(p => new{Id = p, Name = p }), "Id", "Name", allocation.Month);
            }
            else
            {
                ViewBag.Months = new SelectList(Enumerable.Empty<SelectListItem>(), "Id", "Name");
            }
            ViewBag.Transporters = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name",allocation.TransporterID);
            ViewBag.Programs = new SelectList(_commonService.GetAllProgram(), "ProgramID", "Name",allocation.ProgramID);
            ViewBag.Units = new SelectList(_commonService.GetAllUnit(), "UnitID", "Name",allocation.Unit);

               // TODO we can use the line below for debugging and server side validation
            PrepareFDPForEdit(allocation.FDPID);
        }
        public void ShouldCrateDispatchAllocation()
        {
            //Act
            var id = Guid.NewGuid();
            var dispatchAllocation = new DispatchAllocationViewModel()
            {
                CommodityID = 1,
                Amount = 10,
                Beneficiery = 120,
                BidRefNo = "1",
                CommodityTypeID = 1,
                DispatchAllocationID = id,
                DonorID = 1,
                FDPID = 1,
                HubID = 1,
                Month = 1,
                PartitionID = 1,
                ProgramID = 1,
                ProjectCodeID = 1,
                RegionID = 1,
                RequisitionNo = "R-001",
                Round = 1,
                ShippingInstructionID = 1,
                TransporterID = 1,
                Unit = 1,
                WoredaID = 3,
                Year = 2012,
                ZoneID = 2
            };
            _dispatchAllocationController.Create(dispatchAllocation);

            var result = (ViewResult)_dispatchAllocationController.Index();

            //Assert
            Assert.AreEqual(2, ((List<string>)result.Model).Count);
        }
 private DispatchAllocationViewModel GetAllocationModel(DispatchAllocation dispatch)
 {
     //TODO:Make sure if includeproperties are loaded correctly
     var fdp = _fdpService.FindById(dispatch.FDPID);
        DispatchAllocationViewModel model = new DispatchAllocationViewModel(fdp);
     model.Amount = dispatch.Amount;
     model.Beneficiery = dispatch.Beneficiery;
     model.BidRefNo = dispatch.BidRefNo;
     model.CommodityID = dispatch.CommodityID;
     model.DispatchAllocationID = dispatch.DispatchAllocationID;
     model.DonorID = dispatch.DonorID;
     model.FDPID = dispatch.FDPID;
     model.HubID = dispatch.HubID;
     model.Month = dispatch.Month;
     model.PartitionID = dispatch.PartitionID;
     model.ProgramID = dispatch.ProgramID;
     model.ProjectCodeID = dispatch.ProjectCodeID;
     model.RequisitionNo = dispatch.RequisitionNo;
     model.Round = dispatch.Round;
     model.ShippingInstructionID = dispatch.ShippingInstructionID;
     model.TransporterID = dispatch.TransporterID;
     model.Unit = dispatch.Unit;
     model.Year = dispatch.Year;
     model.CommodityTypeID = dispatch.Commodity.CommodityTypeID;
     return model;
 }
        /// <summary>
        /// Gets the allocation model.
        /// </summary>
        /// <param name="dispatch">The dispatch.</param>
        /// <returns></returns>
        private DispatchAllocation GetAllocationModel(DispatchAllocationViewModel dispatch)
        {
            DispatchAllocation model = new DispatchAllocation();
            model.Amount = dispatch.Amount;
            model.Beneficiery = dispatch.Beneficiery;
            model.BidRefNo = dispatch.BidRefNo;
            model.CommodityID = dispatch.CommodityID;
            if(dispatch.DispatchAllocationID.HasValue)
            {
                model.DispatchAllocationID = dispatch.DispatchAllocationID.Value;
            }

            model.DonorID = dispatch.DonorID;
            model.FDPID = dispatch.FDPID;
            model.HubID = dispatch.HubID;
            model.Month = dispatch.Month;
            model.PartitionID = dispatch.PartitionID;
            model.ProgramID = dispatch.ProgramID;
            model.ProjectCodeID = dispatch.ProjectCodeID;
            model.RequisitionNo = dispatch.RequisitionNo;
            model.Round = dispatch.Round;
            model.ShippingInstructionID = dispatch.ShippingInstructionID;
            model.TransporterID = dispatch.TransporterID;
            model.Unit = dispatch.Unit;
            model.Year = dispatch.Year;
            return model;
        }
 public ActionResult SaveFDPAllocationAjax(DispatchAllocationViewModel allocation)
 {
     if (ModelState.IsValid)
     {
         DispatchAllocation alloc = GetAllocationModel(allocation);
         _dispatchAllocationService.EditDispatchAllocation(alloc);
         return Json("{status:1}", JsonRequestBehavior.AllowGet);
     }
     return Json("{status:0}", JsonRequestBehavior.AllowGet);
 }
 public ActionResult Edit(DispatchAllocationViewModel allocation)
 {
     if (ModelState.IsValid)
     {
         DispatchAllocation alloc = GetAllocationModel(allocation);
         _dispatchAllocationService.EditDispatchAllocation(alloc);
         if (this.Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.PathAndQuery);
         else return RedirectToAction("Index");
         //return Json(true, JsonRequestBehavior.AllowGet);
         //return RedirectToAction("Index");
     }
     PrepareEdit(allocation);
     return PartialView(allocation);
 }
 public ActionResult Create(DispatchAllocationViewModel allocation)
 {
     if (ModelState.IsValid)
     {
         var user = _userProfileService.GetUser(User.Identity.Name);
         var alloc = GetAllocationModel(allocation);
         alloc.DispatchAllocationID = Guid.NewGuid();
         alloc.HubID = user.DefaultHub.HubID;
         _dispatchAllocationService.AddDispatchAllocation(alloc);
         if (this.Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.PathAndQuery);
         else return RedirectToAction("Index");
     }
     PrepareEdit(allocation);
     return PartialView("Create",allocation);
 }
 private DispatchAllocationViewModel GetAllocationModelForClose(DispatchAllocation dispatch)
 {
     //TODO:Make sure if includeproperties are loaded correctly
     var fdp = _fdpService.FindById(dispatch.FDPID);
     var donorid = (dispatch.DonorID) ?? -1;
     var donor = (donorid != -1) ? _donorService.FindById(donorid).Name : "-";
     var monthid = (dispatch.Month) ?? -1;
     var month = (monthid != -1) ? Cats.Helpers.RequestHelper.MonthName(monthid) : "-";
     var projectcodeId = (dispatch.ProjectCodeID) ?? -1;
     var projectcodevalue = (projectcodeId != -1) ? _projectCodeService.GetProjectCodeValueByProjectCodeId(projectcodeId) : "-";
     DispatchAllocationViewModel model = new DispatchAllocationViewModel(fdp);
        model.Amount = dispatch.Amount;
        model.BidRefNo = dispatch.BidRefNo;
        model.FDPName = dispatch.FDP.Name;
        model.RequisitionNo = dispatch.RequisitionNo;
        model.Round = dispatch.Round;
        model.Year = dispatch.Year;
        model.ProgramName = dispatch.Program.Name;
        model.CommodityName = dispatch.Commodity.Name;
        model.MonthName = month;
        model.ShippingInstruction = dispatch.ShippingInstruction;
        model.ProjectCodeValue = projectcodevalue;
     model.RemainingQuantityInQuintals = dispatch.RemainingQuantityInQuintals;
     return model;
 }
 private DispatchAllocationViewModel GetAllocationModel(DispatchAllocation dispatch)
 {
     //TODO:Make sure if includeproperties are loaded correctly
     var fdp = _fdpService.FindById(dispatch.FDPID);
     var donorid = (dispatch.DonorID) ?? -1;
     var donor = (donorid != -1) ? _donorService.FindById(donorid).Name : "-";
     var monthid = (dispatch.Month) ?? -1;
     var month = (monthid != -1) ? Cats.Helpers.RequestHelper.MonthName(monthid) : "-";
        DispatchAllocationViewModel model = new DispatchAllocationViewModel(fdp);
     model.Amount = dispatch.Amount;
     model.Beneficiery = dispatch.Beneficiery;
     model.BidRefNo = dispatch.BidRefNo;
     model.CommodityID = dispatch.CommodityID;
     model.DispatchAllocationID = dispatch.DispatchAllocationID;
     model.DonorID = dispatch.DonorID;
     model.FDPID = dispatch.FDPID;
     model.HubID = dispatch.HubID;
     model.Month = dispatch.Month;
     model.PartitionId = dispatch.PartitionId;
     model.ProgramID = dispatch.ProgramID;
     model.ProjectCodeID = dispatch.ProjectCodeID;
     model.RequisitionNo = dispatch.RequisitionNo;
     model.Round = dispatch.Round;
     model.ShippingInstructionID = dispatch.ShippingInstructionID;
     model.TransporterID = dispatch.TransporterID;
     model.Unit = dispatch.Unit;
     model.Year = dispatch.Year;
     model.CommodityTypeID = dispatch.Commodity.CommodityTypeID;
     model.ProgramName = dispatch.Program.Name;
     model.CommodityTypeName = dispatch.Commodity.CommodityType.Name;
     model.CommodityName = dispatch.Commodity.Name;
     model.DonorName = donor;
     model.UnitName = _unitService.FindById(dispatch.Unit) == null ? "-" : _unitService.FindById(dispatch.Unit).Name;
     model.MonthName = month;
     model.TransporterName = dispatch.Transporter.Name;
     return model;
 }