/// <summary> /// Generates the allocation view model. /// </summary> /// <param name="receiptAllocation">The receipt allocation.</param> /// <returns></returns> public static ReceiptAllocationViewModel GenerateAllocationViewModel(BLL.ReceiptAllocation receiptAllocation) { ReceiptAllocationViewModel receiptAllocationViewModel = new ReceiptAllocationViewModel(); receiptAllocationViewModel.ProjectNumber = receiptAllocation.ProjectNumber; receiptAllocationViewModel.CommodityID = receiptAllocation.CommodityID; receiptAllocationViewModel.SINumber = receiptAllocation.SINumber; receiptAllocationViewModel.QuantityInMT = receiptAllocation.QuantityInMT; if (receiptAllocation.QuantityInUnit == null) { receiptAllocationViewModel.QuantityInUnit = 0; } else { receiptAllocationViewModel.QuantityInUnit = receiptAllocation.QuantityInUnit.Value; } receiptAllocationViewModel.HubID = receiptAllocation.HubID; receiptAllocationViewModel.ETA = receiptAllocation.ETA; receiptAllocationViewModel.DonorID = receiptAllocation.DonorID; receiptAllocationViewModel.GiftCertificateDetailID = receiptAllocation.GiftCertificateDetailID; receiptAllocationViewModel.ReceiptAllocationID = receiptAllocation.ReceiptAllocationID; receiptAllocationViewModel.IsCommited = receiptAllocation.IsCommited; receiptAllocationViewModel.SourceHubID = receiptAllocation.SourceHubID; receiptAllocationViewModel.PurchaseOrder = receiptAllocation.PurchaseOrder; receiptAllocationViewModel.SupplierName = receiptAllocation.SupplierName; receiptAllocationViewModel.OtherDocumentationRef = receiptAllocation.OtherDocumentationRef; receiptAllocationViewModel.Remark = receiptAllocation.Remark; receiptAllocationViewModel.CommodityTypeID = receiptAllocation.Commodity.CommodityTypeID; receiptAllocationViewModel.ProgramID = receiptAllocation.ProgramID; receiptAllocationViewModel.CommoditySourceID = receiptAllocation.CommoditySourceID; return(receiptAllocationViewModel); }
public ActionResult Edit(ReceiptAllocationViewModel receiptAllocationViewModel) { if (receiptAllocationViewModel.CommoditySourceID == BLL.CommoditySource.Constants.DONATION) { ModelState.Remove("SourceHubID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } else if (receiptAllocationViewModel.CommoditySourceID == BLL.CommoditySource.Constants.LOCALPURCHASE) { ModelState.Remove("DonorID"); ModelState.Remove("SourceHubID"); } else { ModelState.Remove("DonorID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } if (!(IsSIValid(receiptAllocationViewModel.SINumber, receiptAllocationViewModel.CommoditySourceID))) { ModelState.AddModelError("SINumber", ""); } if (ModelState.IsValid) { BLL.ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation(); int typeOfGridToReload = receiptAllocation.CommoditySourceID; int commType = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID; //override to default hub BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name); receiptAllocation.HubID = user.DefaultHub.HubID; if (typeOfGridToReload != DRMFSS.BLL.CommoditySource.Constants.DONATION && typeOfGridToReload != DRMFSS.BLL.CommoditySource.Constants.LOCALPURCHASE) { typeOfGridToReload = DRMFSS.BLL.CommoditySource.Constants.LOAN; } //TODO:Check savechanges -> EditRecieptAllocation _receiptAllocationService.EditReceiptAllocation(receiptAllocation); return(Json(new { gridId = typeOfGridToReload, CommodityTypeID = commType }, JsonRequestBehavior.AllowGet)); //return RedirectToAction("Index"); } //return this.Create(receiptAllocationViewModel.CommoditySourceID); //ModelState.Remove("SINumber"); //TODO:Check if commenting out has any effect //================================================ // receiptAllocationViewModel.InitalizeViewModel(); //============================================= return(PartialView(receiptAllocationViewModel)); }
public static ReceiptAllocationViewModelDto GenerateAllocationViewModelDto(BLL.ReceiptAllocation receiptAllocation) { ReceiptAllocationViewModelDto receiptAllocationViewModelDto = new ReceiptAllocationViewModelDto(); receiptAllocationViewModelDto.ProjectNumber = receiptAllocation.ProjectNumber; receiptAllocationViewModelDto.CommodityID = receiptAllocation.CommodityID; receiptAllocationViewModelDto.SINumber = receiptAllocation.SINumber; receiptAllocationViewModelDto.QuantityInMT = receiptAllocation.QuantityInMT; receiptAllocationViewModelDto.HubID = receiptAllocation.HubID; receiptAllocationViewModelDto.ETA = receiptAllocation.ETA; if (receiptAllocation.DonorID != null) { receiptAllocationViewModelDto.DonorID = receiptAllocation.DonorID.Value; } if (receiptAllocation.GiftCertificateDetailID != null) { receiptAllocationViewModelDto.GiftCertificateDetailID = receiptAllocation.GiftCertificateDetailID.Value; } receiptAllocationViewModelDto.ReceiptAllocationID = receiptAllocation.ReceiptAllocationID; receiptAllocationViewModelDto.IsCommited = receiptAllocation.IsCommited; if (receiptAllocation.SourceHubID != null) { receiptAllocationViewModelDto.SourceHubID = receiptAllocation.SourceHubID.Value; } receiptAllocationViewModelDto.PurchaseOrder = receiptAllocation.PurchaseOrder; receiptAllocationViewModelDto.SupplierName = receiptAllocation.SupplierName; receiptAllocationViewModelDto.OtherDocumentationRef = receiptAllocation.OtherDocumentationRef; receiptAllocationViewModelDto.Remark = receiptAllocation.Remark; receiptAllocationViewModelDto.ProgramID = receiptAllocation.ProgramID; receiptAllocationViewModelDto.CommoditySourceID = receiptAllocation.CommoditySourceID; receiptAllocationViewModelDto.CommodityName = receiptAllocation.CommodityName; receiptAllocationViewModelDto.ReceivedQuantityInMT = receiptAllocation.ReceivedQuantityInMT; receiptAllocationViewModelDto.RemainingBalanceInMt = receiptAllocation.RemainingBalanceInMt; return(receiptAllocationViewModelDto); }
public ActionResult Create(ReceiptAllocationViewModel receiptAllocationViewModel) { if (receiptAllocationViewModel.CommoditySourceID == BLL.CommoditySource.Constants.DONATION) { ModelState.Remove("SourceHubID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } else if (receiptAllocationViewModel.CommoditySourceID == BLL.CommoditySource.Constants.LOCALPURCHASE) { ModelState.Remove("DonorID"); ModelState.Remove("SourceHubID"); } else { ModelState.Remove("DonorID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } if (!(IsSIValid(receiptAllocationViewModel.SINumber, receiptAllocationViewModel.CommoditySourceID))) { ModelState.AddModelError("SINumber", ""); } if (ModelState.IsValid) { BLL.ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation(); //for creation make the giftCetificate null if it's from if (receiptAllocationViewModel.GiftCertificateDetailID == 0 || receiptAllocationViewModel.GiftCertificateDetailID == null ) { var GC = _giftCertificateService.FindBySINumber(receiptAllocationViewModel.SINumber); if (GC != null) { var GCD = GC.GiftCertificateDetails.FirstOrDefault( p => p.CommodityID == receiptAllocationViewModel.CommodityID); if (GCD != null) //&& GCD.GiftCertificateDetailID; { receiptAllocation.GiftCertificateDetailID = GCD.GiftCertificateDetailID; } } else { receiptAllocation.GiftCertificateDetailID = null; } } int typeOfGridToReload = receiptAllocation.CommoditySourceID; int commType = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID; //override to default hub BLL.UserProfile user = _userProfileService.GetUser(User.Identity.Name); receiptAllocation.HubID = user.DefaultHub.HubID; if (typeOfGridToReload != DRMFSS.BLL.CommoditySource.Constants.DONATION && typeOfGridToReload != DRMFSS.BLL.CommoditySource.Constants.LOCALPURCHASE) { typeOfGridToReload = DRMFSS.BLL.CommoditySource.Constants.LOAN; } _receiptAllocationService.AddReceiptAllocation(receiptAllocation); return(Json(new { gridId = typeOfGridToReload, CommodityTypeID = commType }, JsonRequestBehavior.AllowGet)); //return RedirectToAction("Index"); } //check this out later //return this.Create(receiptAllocationViewModel.CommoditySourceID); //ModelState.Remove("SINumber"); //TODO:Check if commenting out has any effect //================================================= //receiptAllocationViewModel.InitalizeViewModel(); //================================================ return(PartialView(receiptAllocationViewModel)); }