Esempio n. 1
0
        public ActionResult SelectDispatchsCommodities(string dispatchId)
        {
            var commodities = new List <DispatchDetailModel>();

            if (dispatchId != null)
            {
                var user = _userProfileService.GetUser(User.Identity.Name);
                commodities = DispatchDetailModel.GenerateDispatchDetailModels(_dispatchService.FindById(Guid.Parse(dispatchId)).DispatchDetails);
                //commodities = (from c in repository.DispatchDetail.GetDispatchDetail(Guid.Parse(dispatchId))
                //              select new Models.DispatchDetailModel()
                //              {
                //                  CommodityID = c.CommodityID,
                //                  CommodityName = c.Commodity.Name,
                //                  Description = c.Description,
                //                  Id = c.DispatchDetailID,
                //                  DispatchedQuantityMT = c.DispatchedQuantityInMT,
                //                  RequestedQuantityMT = c.RequestedQuantityInMT,
                //                  RequestedQuantity = c.RequestedQunatityInUnit,
                //                  DispatchedQuantity = c.DispatchedQuantityInUnit,
                //                  Unit = c.UnitID,
                //                 // DispatchID = c.DispatchID
                //              }).ToList();

                foreach (var gridCommodities in commodities)
                {
                    if (user.PreferedWeightMeasurment.Equals("qn"))
                    {
                        gridCommodities.DispatchedQuantityMT *= 10;
                        gridCommodities.RequestedQuantityMT  *= 10;
                    }
                }

                string str = Request["prev"];
                if (GetSelectedCommodities(str) != null)
                {
                    // TODO: revise this section
                    var allCommodities = GetSelectedCommodities(Request["prev"].ToString(CultureInfo.InvariantCulture));
                    var count          = -1;
                    foreach (var dispatchDetailViewModelComms in allCommodities)
                    {
                        if (dispatchDetailViewModelComms.Id == null)
                        {
                            //dispatchDetailViewModelComms.Id = count--;
                            dispatchDetailViewModelComms.DispatchDetailCounter = count--;
                            commodities.Add(dispatchDetailViewModelComms);
                        }
                        //
                        // TODO the lines below are too nice to have but we need to look into the performance issue and
                        // policies (i.e. editing should not be allowed ) may be only for quanitities
                        //
                        else //replace the commodity read from the db by what's comming from the user
                        {
                            commodities.Remove(commodities.Find(p => p.Id == dispatchDetailViewModelComms.Id));
                            commodities.Add(dispatchDetailViewModelComms);
                        }
                    }
                }
            }
            else
            {
                string str = Request["prev"];
                if (GetSelectedCommodities(str) != null)
                {
                    commodities = GetSelectedCommodities(Request["prev"].ToString(CultureInfo.InvariantCulture));
                    int count = -1;
                    foreach (var rdm in commodities)
                    {
                        if (rdm.Id != null)
                        {
                            rdm.DispatchDetailCounter = count--;
                        }
                    }
                }
            }

            ViewBag.Commodities = _commodityService.GetAllParents().Select(c => new Models.CommodityModel()
            {
                Id = c.CommodityID, Name = c.Name
            }).ToList();
            //TODO do we really need the line below
            //PrepareCreate(1);
            return(View(new GridModel(commodities)));
        }