This is a partial class to the Dispatch entity
예제 #1
0
        private void PrepareEdit(Dispatch dispatch, UserProfile user, int type)
        {
            var years = (from y in _periodService.GetYears()
                         select new { Name = y, Id = y }).ToList();
            var months = (from y in _periodService.GetMonths(dispatch.PeriodYear)
                         select new { Name = y, Id = y }).ToList();
            ViewBag.Year = new SelectList(years, "Id", "Name", dispatch.PeriodYear);
            ViewBag.Month = new SelectList(months, "Id", "Name", dispatch.PeriodMonth);
            ViewData["Units"] = _unitService.GetAllUnit().Select(p => new { Id = p.UnitID, p.Name}).ToList();
            var transaction = _dispatchService.GetDispatchTransaction(dispatch.DispatchID);

            ViewBag.TransporterID = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name", dispatch.TransporterID);
            if (type == 1)
            {
                PrepareFDPForEdit(dispatch.FDPID);
            }
            else if (type == 2)
            {
                var tran = _dispatchService.GetDispatchTransaction(dispatch.DispatchID);
                //TODO I think there need's to be a check for this one
                ViewBag.ToHUBs = tran != null ? new SelectList(_hubService.GetAllHub().Select(p => new {Name = string.Format("{0} - {1}",p.Name,p.HubOwner.Name), HubID = p.HubID}), "HubID", "Name", tran.Account.EntityID) : null;
            }

            if (transaction != null)
            {
                ViewBag.StoreID = new SelectList(_storeService.GetStoreByHub(user.DefaultHub.HubID), "StoreID", "Name", transaction.StoreID);
                ViewBag.ProgramID = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name", transaction.ProgramID);
                if (transaction.Stack != null)
                    ViewBag.StackNumbers = new SelectList(transaction.Store.Stacks.Select(p => new { Name = p, Id = p }), "Id", "Name", transaction.Stack.Value);
                ViewData["Commodities"] = _commodityService.GetAllParents().Select(c => new CommodityModel { Id = c.CommodityID, Name = c.Name }).ToList();
                ViewBag.CommodityTypeID = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name",transaction.Commodity.CommodityTypeID);
            }
            else
            {
                ViewBag.StoreID = new SelectList(_storeService.GetStoreByHub(user.DefaultHub.HubID), "StoreID",
                                                 "Name"); //, transaction.StoreID);
                ViewBag.ProgramID = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name");
                    //, transaction.ProgramID);
                //TODO i'm not so sure about the next line
                var firstOrDefault = _storeService.GetAllStore().FirstOrDefault();
                if (firstOrDefault != null)
                    ViewBag.StackNumbers =
                        new SelectList(firstOrDefault.Stacks.Select(p => new {Name = p, Id = p}), "Id",
                                       "Name"); //, transaction.Stack.Value); )//transaction.Store.Stacks
                ViewData["Commodities"] =
                    _commodityService.GetAllParents().Select(
                        c => new CommodityModel {Id = c.CommodityID, Name = c.Name}).ToList();
                ViewBag.CommodityTypeID = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name");
            }
            var comms = new List<DispatchDetailModel>();
            ViewBag.SelectedCommodities = comms;
        }
예제 #2
0
 public ActionResult Edit(Dispatch dispatch)
 {
     if (ModelState.IsValid)
     {
         _dispatchService.EditDispatch(dispatch);
         return RedirectToAction("Index");
     }
     ViewBag.PeriodID = new SelectList(_periodService.GetAllPeriod(), "PeriodID", "PeriodID", _periodService.GetPeriod(dispatch.PeriodYear, dispatch.PeriodMonth).PeriodID);
     var user = _userProfileService.GetUser(User.Identity.Name);
     ViewBag.StoreID = new SelectList(_storeService.GetStoreByHub(user.DefaultHub.HubID), "StoreID", "Name");
     ViewBag.TransporterID = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name", dispatch.TransporterID);
     ViewBag.HubID = new SelectList(user.UserHubs, "HubID", "Name", dispatch.HubID);
     ViewBag.CommodityTypeID = new SelectList(_commodityTypeService.GetAllCommodityType(), "CommodityTypeID", "Name");
     return View(dispatch);
 }