public ActionResult Create(string receiptAllocationId, string grn) { if (grn != null) { return(View(ModeltoNewView(_receiveService.FindById(Guid.Parse(receiptAllocationId))))); } if (String.IsNullOrEmpty(receiptAllocationId)) { return(View()); } _receiptAllocationId = Guid.Parse(receiptAllocationId); var receiptAllocation = _receiptAllocationService.FindById(_receiptAllocationId); var user = _userProfileService.GetUser(User.Identity.Name); if (receiptAllocation == null || (user.DefaultHub == null || receiptAllocation.HubID != user.DefaultHub.Value)) { return(View()); } var viewModel = _receiveService.ReceiptAllocationToReceive(receiptAllocation); viewModel.CurrentHub = user.DefaultHub.Value; viewModel.UserProfileId = user.UserProfileID; var hubOwner = _hub.FindById(user.DefaultHub.Value); viewModel.IsTransporterDetailVisible = !hubOwner.HubOwner.Name.Contains("WFP"); viewModel.AllocationStatusViewModel = _receiveService.GetAllocationStatus(_receiptAllocationId); //var commodities = _commodityService.GetAllCommodityViewModelsByParent(receiptAllocation.CommodityID); //ViewData["commodities"] = commodities; //ViewData["units"] = _unitService.GetAllUnitViewModels(); //viewModel.ReceiveDetailNewViewModel.CommodityId = receiptAllocation.CommodityID; //since the commodity that comes from allocation is the child look for the parent for saving later. var parentCommodityId = _commodityService.FindById(receiptAllocation.CommodityID).ParentID ?? receiptAllocation.CommodityID; viewModel.ReceiveDetailNewViewModel = new ReceiveDetailNewViewModel { CommodityId = parentCommodityId, CommodityChildID = receiptAllocation.CommodityID, //UnitId=receiptAllocation.UnitID.GetValueOrDefault(), }; return(View(viewModel)); }