public ViewModels.Dispatch.OtherDispatchAllocationViewModel GetViewModelByID(Guid otherDispatchAllocationId)
 {
     var  OtherDispach =  _unitOfWork.OtherDispatchAllocationRepository.Get();
     var model = (from v in OtherDispach
                  where v.OtherDispatchAllocationID == otherDispatchAllocationId
                  select v).FirstOrDefault();
     if (model != null)
     {
         var val = new OtherDispatchAllocationViewModel()
         {
             PartitionID = 0,
             OtherDispatchAllocationID = model.OtherDispatchAllocationID,
             ProgramID = model.ProgramID,
             FromHubID = model.HubID,
             ToHubID = model.ToHubID,
             ReasonID = model.ReasonID,
             ReferenceNumber = model.ReferenceNumber,
             AgreementDate = model.AgreementDate,
             CommodityID = model.CommodityID,
             EstimatedDispatchDate = model.EstimatedDispatchDate,
             IsClosed = model.IsClosed,
             ProjectCode = model.ProjectCode.Value,
             ShippingInstruction = model.ShippingInstruction.Value,
             UnitID = model.UnitID,
             QuantityInUnit = model.QuantityInUnit,
             QuantityInMT = model.QuantityInMT,
             CommodityTypeID = model.Commodity.CommodityTypeID,
             Remark = model.Remark,
         };
         return val;
     }
     return null;
 }
        private OtherDispatchAllocationViewModel InitTransfer(OtherDispatchAllocationViewModel otherDispatchAllocationViewModel)
        {
            var user = _userProfileService.GetUser(User.Identity.Name);
            var tohubs = _hubService.GetOthersHavingSameOwner(user.DefaultHub);

            var commodities = _commonService.GetAllParents();
            var commodityTypes = _commodityTypeService.GetAllCommodityType();
            var programs = _commonService.GetAllProgram();
            var units = _commonService.GetAllUnit();

            otherDispatchAllocationViewModel.InitTransfer(user, tohubs, commodities, commodityTypes, programs, units);
            return otherDispatchAllocationViewModel;
        }
 public ActionResult SaveTransfer(OtherDispatchAllocationViewModel model)
 {
     BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name);
     model.FromHubID = user.DefaultHub.HubID;
     if (ModelState.IsValid)
     {
         _otherDispatchAllocationService.Save(model);
         if (this.Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.PathAndQuery);
         else return RedirectToAction("ToHubs");
         //return RedirectToAction("ToHubs");
     }
     else
     {
        // model.InitTransfer(_userProfileService.GetUser(User.Identity.Name), repository);
         return PartialView("EditTransfer", InitTransfer(model));
     }
 }
        public ActionResult CreateTransfer()
        {
            var model = new OtherDispatchAllocationViewModel();

            return PartialView("EditTransfer", InitTransfer(model));
        }
 public ActionResult CreateLoan()
 {
     var model = new OtherDispatchAllocationViewModel();
        // model.InitLoan(_userProfileService.GetUser(User.Identity.Name), repository);
     return PartialView("EditLoans",InitLoan(model));
 }
        public void SouldSaveLoan()
        {
            //Arrange
            var id = Guid.NewGuid();
            var dispatchAllocation = new OtherDispatchAllocationViewModel()
            {
                CommodityID = 1,
                CommodityTypeID = 1,
                PartitionID = 1,
                ProgramID = 1,
                AgreementDate = DateTime.Today,
                EstimatedDispatchDate = DateTime.Today.AddDays(3),
                FromHubID = 2,
                ToHubID = 1,
                IsClosed = true,
                OtherDispatchAllocationID = id,
                ProjectCode = "P-001",
                QuantityInMT = 12,
                QuantityInUnit = 12,
                ReasonID = 1,
                ReferenceNumber = "Rf-001",
                UnitID = 1

            };
            //Act

            var result = _dispatchAllocationController.SaveLoan(dispatchAllocation);

            //Assert
            Assert.IsInstanceOf<RedirectToRouteResult>(result);
        }