Ejemplo n.º 1
0
        public ActionResult OtherClose(string id)
        {
            var closeAllocation = _otherDispatchAllocationService.FindById(Guid.Parse(id));

            return(PartialView("CloseOther", closeAllocation));
        }
Ejemplo n.º 2
0
        //
        // GET: /Dispatch/Create

        public ActionResult Create(string ginNo, int type)
        {
            ViewBag.Units = _unitService.GetAllUnit();

            var dispatch = _dispatchService.GetDispatchByGIN(ginNo);
            var user     = _userProfileService.GetUser(User.Identity.Name);

            if (dispatch != null)
            {
                if (user.DefaultHub != null && user.DefaultHub.HubID == dispatch.HubID)
                {
                    PrepareEdit(dispatch, user, type);
                    var transaction = _dispatchService.GetDispatchTransaction(dispatch.DispatchID);
                    var dis         = DispatchModel.GenerateDispatchModel(dispatch, transaction);
                    return(View(dis));
                }
                PrepareCreate(type);
                var comms = new List <DispatchDetailModel>();
                ViewBag.SelectedCommodities = comms;
                var theViewModel = new DispatchModel {
                    Type = type, DispatchDetails = comms
                };
                ViewBag.Message = "The selected GIN Number doesn't exist on your default warehouse. Try changing your default warehouse.";
                return(View(theViewModel));
            }
            else
            {
                PrepareCreate(type);
                var comms = new List <DispatchDetailModel>();
                ViewBag.SelectedCommodities = comms;
                var theViewModel = new DispatchModel {
                    Type = type, DispatchDetails = comms
                };

                if (Request["type"] != null && Request["allocationId"] != null)
                {
                    var allocationId     = Guid.Parse(Request["allocationId"]);
                    var allocationTypeId = Convert.ToInt32(Request["type"]);

                    if (allocationTypeId == 1)//to FDP
                    {
                        DispatchAllocation toFDPDispatchAllocation = _dispatchAllocationService.FindById(allocationId);

                        theViewModel.FDPID = toFDPDispatchAllocation.FDPID;
                        PrepareFDPForEdit(toFDPDispatchAllocation.FDPID);

                        theViewModel.RequisitionNo = toFDPDispatchAllocation.RequisitionNo;
                        theViewModel.BidNumber     = toFDPDispatchAllocation.BidRefNo;
                        theViewModel.SINumber      = toFDPDispatchAllocation.ShippingInstruction.Value;
                        theViewModel.ProjectNumber = toFDPDispatchAllocation.ProjectCode.Value;

                        theViewModel.CommodityTypeID = toFDPDispatchAllocation.Commodity.CommodityTypeID;
                        ViewBag.CommodityTypeID      = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name", toFDPDispatchAllocation.Commodity.CommodityTypeID);

                        if (toFDPDispatchAllocation.ProgramID.HasValue)
                        {
                            theViewModel.ProgramID = toFDPDispatchAllocation.ProgramID.Value;
                            ViewBag.ProgramID      = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name", theViewModel.ProgramID);
                        }
                        if (toFDPDispatchAllocation.TransporterID.HasValue)
                        {
                            theViewModel.TransporterID = toFDPDispatchAllocation.TransporterID.Value;
                        }
                        ViewBag.TransporterID = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name", theViewModel.TransporterID);
                        if (toFDPDispatchAllocation.Year.HasValue)
                        {
                            theViewModel.Year = toFDPDispatchAllocation.Year.Value;
                        }
                        var years = (from y in _periodService.GetYears()
                                     select new { Name = y, Id = y }).ToList();
                        ViewBag.Year = new SelectList(years, "Id", "Name");
                        ViewBag.Year = new SelectList(years, "Id", "Name", theViewModel.Year);
                        if (toFDPDispatchAllocation.Month.HasValue)
                        {
                            theViewModel.Month = toFDPDispatchAllocation.Month.Value;
                        }
                        var months = (from y in _periodService.GetMonths(theViewModel.Year)
                                      select new { Name = y, Id = y }).ToList();
                        ViewBag.Month = new SelectList(months, "Id", "Name", theViewModel.Month);
                        if (toFDPDispatchAllocation.Round.HasValue)
                        {
                            theViewModel.Round = toFDPDispatchAllocation.Round.Value;
                        }
                        theViewModel.DispatchAllocationID = toFDPDispatchAllocation.DispatchAllocationID;
                    }
                    else //allocationTypeId == 2
                    {
                        var otherDispatchAllocation = _otherDispatchAllocationService.FindById(allocationId);
                        theViewModel.ToHubID       = otherDispatchAllocation.ToHubID;
                        theViewModel.SINumber      = otherDispatchAllocation.ShippingInstruction.Value;
                        theViewModel.ProjectNumber = otherDispatchAllocation.ProjectCode.Value;
                        theViewModel.ProgramID     = otherDispatchAllocation.ProgramID;

                        theViewModel.CommodityTypeID = otherDispatchAllocation.Commodity.CommodityTypeID;
                        ViewBag.CommodityTypeID      = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name", otherDispatchAllocation.Commodity.CommodityTypeID);

                        ViewBag.ProgramID = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name", theViewModel.ProgramID);
                        theViewModel.OtherDispatchAllocationID = otherDispatchAllocation.OtherDispatchAllocationID;
                    }
                }

                return(View(theViewModel));
            }
        }