private bool SaveNewDonationPlan(DonationViewModel donationViewModel,int siId) { try { var donationHeader = new DonationPlanHeader { AllocationDate = DateTime.Now, CommodityID = donationViewModel.CommodityID, DonorID = donationViewModel.DonorID, ETA = donationViewModel.ETA, IsCommited = false, ProgramID = donationViewModel.ProgramID, ShippingInstructionId = siId, DonatedAmount = donationViewModel.WieghtInMT, CommodityTypeID = donationViewModel.CommodityTypeID }; foreach (var donationDetail in donationViewModel.DonationPlanDetails.Select(donationPlanDetail => new DonationPlanDetail { HubID = donationPlanDetail.HubID, AllocatedAmount = donationPlanDetail.AllocatedAmount, ReceivedAmount = donationPlanDetail.ReceivedAmount, Balance = donationPlanDetail.Balance, DonationPlanHeader = donationHeader })) { _donationPlanDetailService.AddDonationPlanDetail(donationDetail); } _transactionService.PostDonationPlan(donationHeader); return true; } catch (Exception) { return false; } }
private bool UpdateDonationPlan(DonationViewModel donationViewModel, int shippinInstructionId) { try { var index = 0; var donation = _donationPlanDetailService.FindBy(s => s.DonationPlanHeader.ShippingInstructionId == shippinInstructionId).ToList(); if (donation.Count > 0) { var detailArray = donationViewModel.DonationPlanDetails.ToArray(); foreach (var donationPlanDetail in donation) { donationPlanDetail.DonationPlanHeader.AllocationDate = DateTime.Now; donationPlanDetail.DonationPlanHeader.CommodityID = donationViewModel.CommodityID; donationPlanDetail.DonationPlanHeader.DonorID = donationViewModel.DonorID; donationPlanDetail.DonationPlanHeader.ETA = donationPlanDetail.DonationPlanHeader.ETA; donationPlanDetail.DonationPlanHeader.IsCommited = false; donationPlanDetail.DonationPlanHeader.ProgramID = donationViewModel.ProgramID; donationPlanDetail.DonationPlanHeader.ShippingInstructionId = shippinInstructionId; donationPlanDetail.DonationPlanHeader.DonatedAmount = donationViewModel.WieghtInMT; donationPlanDetail.DonationPlanHeader.CommodityTypeID = donationViewModel.CommodityTypeID; donationPlanDetail.AllocatedAmount = detailArray[index].AllocatedAmount; donationPlanDetail.ReceivedAmount = detailArray[index].ReceivedAmount; donationPlanDetail.Balance = detailArray[index].Balance; donationPlanDetail.HubID = detailArray[index].HubID; // donationPlanDetail.DonationPlanHeader = donation; _donationPlanDetailService.EditDonationPlanDetail(donationPlanDetail); index++; } return true; } return false; } catch (Exception) { return false; } }
private DonationViewModel InitDonationViewModel() { var program = _commonService.GetPrograms().ToList(); var donor = _commonService.GetDonors().ToList(); var hub = _hubService.GetAllHub().ToList(); var commodityType = _commodityTypeService.GetAllCommodityType(); var commodity = _commodityService.GetAllCommodity(); var donationViewModel = new DonationViewModel(commodity, donor, hub, program, commodityType) { DonationPlanDetails = GetNewDonationDetail(), ETA = DateTime.Now }; return donationViewModel; }
public ActionResult Save(DonationViewModel donationViewModel) { var program = _commonService.GetPrograms().ToList(); var donor = _commonService.GetDonors().ToList(); var hub = _hubService.GetAllHub().ToList(); var commodityType = _commodityTypeService.GetAllCommodityType(); var commodity = _commodityService.GetAllCommodity(); if (ModelState.IsValid && donationViewModel != null && donationViewModel.WieghtInMT >=donationViewModel.DonationPlanDetails.Sum(m=>m.AllocatedAmount)) { var siId = DoesSIExistInShippingInstruction(donationViewModel.SINumber); if (siId != 0) { if (!DoesSIExistInDonationHeader(donationViewModel.SINumber)) { SaveNewDonationPlan(donationViewModel, siId); } else { UpdateDonationPlan(donationViewModel, siId); } } else { var si = InsertInToShippingInstructionTable(donationViewModel.SINumber); //first in shippins instruction table if (si != -1) SaveNewDonationPlan(donationViewModel, si); // second in doation table } donationViewModel.Donors = donor; donationViewModel.Commodities = commodity; donationViewModel.Programs = program; donationViewModel.CommodityTypes = commodityType; ModelState.AddModelError("Success", @"Receipt Plan has been saved"); return View("AddNewDonationPlan", donationViewModel); } ModelState.AddModelError("Errors", @"Total Allocated Amount Can't Exceed Gift Certificate Amount"); donationViewModel.Donors = donor; donationViewModel.Commodities = commodity; donationViewModel.Programs = program; donationViewModel.CommodityTypes = commodityType; return View("AddNewDonationPlan",donationViewModel); }
private bool UpdateDonationPlan(DonationViewModel donationViewModel, int shippinInstructionId) { try { var index = 0; var donation = _donationPlanHeaderService.FindBy(s => s.ShippingInstructionId == shippinInstructionId).SingleOrDefault(); if (donation!=null) { donation.AllocationDate = DateTime.Now; donation.CommodityID = donationViewModel.CommodityID; donation.DonorID = donationViewModel.DonorID; donation.ETA = donation.ETA; donation.IsCommited = false; donation.ProgramID = donationViewModel.ProgramID; donation.ShippingInstructionId = shippinInstructionId; var detailArray = donationViewModel.DonationPlanDetails.ToArray(); foreach (var donationPlanDetail in donation.DonationPlanDetails) { donationPlanDetail.AllocatedAmount = detailArray[index].AllocatedAmount; donationPlanDetail.ReceivedAmount = detailArray[index].ReceivedAmount; donationPlanDetail.Balance = detailArray[index].Balance; donationPlanDetail.HubID = detailArray[index].HubID; donationPlanDetail.DonationPlanHeader = donation; _donationPlanDetailService.EditDonationPlanDetail(donationPlanDetail); } return true; } return false; } catch (Exception) { return false; } }
public ActionResult Save(DonationViewModel donationViewModel) { if (ModelState.IsValid) { if (donationViewModel != null) { var siId = DoesSIExistInShippingInstruction(donationViewModel.SINumber); if (siId != 0) { if (!DoesSIExistInDonationHeader(donationViewModel.SINumber)) { SaveNewDonationPlan(donationViewModel, siId); } else { UpdateDonationPlan(donationViewModel, siId); } } else { var si = InsertInToShippingInstructionTable(donationViewModel.SINumber); //first in shippins instruction table if (si != -1) SaveNewDonationPlan(donationViewModel, si); // second in doation table } } return RedirectToAction("Index"); } var model = InitDonationViewModel(); return View("AddNewDonationPlan",model); }
public ActionResult Save(DonationViewModel donationViewModel) { if (ModelState.IsValid) { if (donationViewModel != null) { var siId = DoesSIExistInShippingInstruction(donationViewModel.SINumber); if (siId != 0) { if (!DoesSIExistInDonationHeader(donationViewModel.SINumber)) { SaveNewDonationPlan(donationViewModel, siId); } else { UpdateDonationPlan(donationViewModel, siId); } } else { var si = InsertInToShippingInstructionTable(donationViewModel.SINumber); //first in shippins instruction table if (si != -1) SaveNewDonationPlan(donationViewModel, si); // second in doation table } } var program = _commonService.GetPrograms().ToList(); var donor = _commonService.GetDonors().ToList(); var hub = _hubService.GetAllHub().ToList(); var commodityType = _commodityTypeService.GetAllCommodityType(); var commodity = _commodityService.GetAllCommodity(); donationViewModel.Donors = donor; donationViewModel.Commodities = commodity; donationViewModel.Programs = program; donationViewModel.CommodityTypes = commodityType; ModelState.AddModelError("Success", "Receipt Plan has been saved"); return View("AddNewDonationPlan", donationViewModel); } var model = InitDonationViewModel(); return View("AddNewDonationPlan",model); }