public ActionResult AddNewDonationPlan(Cats.Models.Hubs.ReceiptAllocationViewModel receiptAllocationViewModel) { ModelState.Remove("SourceHubID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); if (ModelState.IsValid) { var receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation(); if (receiptAllocationViewModel.GiftCertificateDetailID == 0 || receiptAllocationViewModel.GiftCertificateDetailID == null) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == receiptAllocationViewModel.SINumber).FirstOrDefault(); var gc = new Cats.Models.GiftCertificate(); if (shippingInstruction != null) { gc = _giftCertificateService.FindBySINumber(shippingInstruction.Value); } if (gc != null) { var gcd = gc.GiftCertificateDetails.FirstOrDefault(p => p.CommodityID == receiptAllocationViewModel.CommodityID); if (gcd != null) { receiptAllocation.GiftCertificateDetailID = gcd.GiftCertificateDetailID; } } else { receiptAllocation.GiftCertificateDetailID = null; } } receiptAllocation.HubID = receiptAllocationViewModel.HubID; receiptAllocation.CommoditySourceID = Cats.Models.Hubs.CommoditySource.Constants.DONATION; receiptAllocation.ReceiptAllocationID = Guid.NewGuid(); _receiptAllocationService.AddReceiptAllocation(receiptAllocation); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
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)); }