public ActionResult Edit(ReceiptAllocationViewModel receiptAllocationViewModel) { if (receiptAllocationViewModel.CommoditySourceID ==CommoditySource.Constants.DONATION) { ModelState.Remove("SourceHubID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } else if (receiptAllocationViewModel.CommoditySourceID ==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) { ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation(); int typeOfGridToReload = receiptAllocation.CommoditySourceID; int commType = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID; //override to default hub UserProfile user = _userProfileService.GetUser(User.Identity.Name); receiptAllocation.HubID = user.DefaultHub.HubID; if (typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.DONATION && typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.LOCALPURCHASE) { typeOfGridToReload = Cats.Models.Hubs.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 ActionResult Create(ReceiptAllocationViewModel receiptAllocationViewModel) { if (receiptAllocationViewModel.CommoditySourceID ==CommoditySource.Constants.DONATION) { ModelState.Remove("SourceHubID"); ModelState.Remove("SupplierName"); ModelState.Remove("PurchaseOrder"); } else if (receiptAllocationViewModel.CommoditySourceID ==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) { ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation(); //for creation make the giftCetificate null if it's from if (receiptAllocationViewModel.GiftCertificateDetailID == 0 || receiptAllocationViewModel.GiftCertificateDetailID == null ) { var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == receiptAllocationViewModel.SINumber). FirstOrDefault(); var GC = new Cats.Models.Hubs.GiftCertificate(); if(shippingInstruction!=null) GC = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID); 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 UserProfile user = _userProfileService.GetUser(User.Identity.Name); receiptAllocation.HubID = user.DefaultHub.HubID; if (typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.DONATION && typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.LOCALPURCHASE) { typeOfGridToReload = Cats.Models.Hubs.CommoditySource.Constants.LOAN; } receiptAllocation.ReceiptAllocationID = Guid.NewGuid(); _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); }