public bool EffectPosting(PaymentRequest rfp, Staff poster) { using (var context = SCMSEntities.Define()) { using (TransactionScope scope = new TransactionScope()) { try { var rfpCommits = context.BudgetCommitments.Where(b => b.PaymentRequestBudgetLine.PaymentRequestId == rfp.Id).ToList(); foreach (var rfpCommit in rfpCommits) { var pb = rfpCommit.ProjectBudget; pb.TotalCommitted -= rfpCommit.AmountCommitted; var posting = new BudgetPosting(); posting.AmountPosted = rfpCommit.AmountCommitted; posting.DatePosted = DateTime.Now; posting.Id = Guid.NewGuid(); posting.PostedBy = poster.Id; posting.RFPBudgetLineId = rfpCommit.RFPBudgetLineId; pb.TotalPosted += posting.AmountPosted; //Delete commitment and add posting context.BudgetCommitments.Remove(rfpCommit); context.BudgetPostings.Add(posting); } var paymentRequest = context.PaymentRequests.FirstOrDefault(a => a.Id == rfp.Id); paymentRequest.FundsPosted = true; paymentRequest.PostedBy = poster.Id; paymentRequest.PostedOn = DateTime.Now; //SAVE ALL CHANGES if (context.SaveChanges() > 0) { scope.Complete(); return(true); } else { scope.Dispose(); return(false); } } catch (Exception ex) { scope.Dispose(); throw ex; } } } }
/// <summary> /// BudgetPosting Id is passed /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult RebookPostedAmount(Guid id) { BudgetPosting bp = budgetService.GetBudgetPostingById(id); SCMS.UI.Models.RebookModel model = new SCMS.UI.Models.RebookModel { CurrentBudgetLine = bp, NewBudgetLine = new BudgetPosting(), CurrentProjectId = bp.PaymentRequestBudgetLine.ProjectBudget.BudgetCategory.ProjectDonor.Id, FullRebooking = true, AmountRebooked = Math.Round(bp.AmountPosted, 2), Projects = new SelectList(orderRequestService.GetProject(), "Id", "Name"), ProjectDonors = new SelectList(orderRequestService.GetProjectNos(Guid.Empty), "Id", "ProjectNumber"), BudgetLines = new SelectList(orderRequestService.GetProjectBugdetLines(Guid.Empty), "Id", "Description") }; return(View("RebookBL", model)); }