public object UpdateContribution(PostBundleController ctl) { var c = DbUtil.Db.Contributions.SingleOrDefault(cc => cc.ContributionId == editid); if (c == null) { return(null); } var identifier = DbUtil.Db.CardIdentifiers.SingleOrDefault(ci => ci.Id == c.BankAccount); if (identifier != null) { identifier.PeopleId = pid.ToInt2(); } var type = c.ContributionTypeId; switch (PLNT) { case "PL": type = ContributionTypeCode.Pledge; break; case "NT": type = ContributionTypeCode.NonTaxDed; break; case "GK": type = ContributionTypeCode.GiftInKind; break; case "SK": type = ContributionTypeCode.Stock; break; default: type = ContributionTypeCode.CheckCash; break; } c.FundId = fund; // c.CampusId = campusid; c.PeopleId = pid.ToInt2(); c.ContributionAmount = amt; c.ContributionTypeId = type; c.ContributionDesc = notes; c.ContributionDate = contributiondate; c.CheckNo = checkno?.Trim(); DbUtil.Db.SubmitChanges(); return(ContributionRowData(ctl, c.ContributionId)); }
public object ContributionRowData(PostBundleController ctl, int cid, decimal?othersplitamt = null) { var cinfo = FetchContributions(cid).Single(); var body = ViewExtensions2.RenderPartialViewToString(ctl, "Row", cinfo); var q = from c in DbUtil.Db.Contributions let bh = c.BundleDetails.First().BundleHeader where c.ContributionId == cid select new { row = body, amt = c.ContributionAmount.ToString2("N2"), cid, totalitems = bh.BundleDetails.Sum(d => d.Contribution.ContributionAmount).ToString2("N2"), itemcount = bh.BundleDetails.Count(), othersplitamt = othersplitamt.ToString2("N2") }; return(q.First()); }
public object PostContribution(PostBundleController ctl) { try { var bd = new BundleDetail { BundleHeaderId = id, CreatedBy = Util.UserId, CreatedDate = DateTime.Now }; int type; switch (PLNT) { case "PL": type = ContributionTypeCode.Pledge; break; case "NT": type = ContributionTypeCode.NonTaxDed; break; case "GK": type = ContributionTypeCode.GiftInKind; break; case "SK": type = ContributionTypeCode.Stock; break; default: type = ContributionTypeCode.CheckCash; break; } decimal?othersplitamt = null; if (splitfrom > 0) { var q = from c in DbUtil.Db.Contributions where c.ContributionId == splitfrom select new { c, bd = c.BundleDetails.First() }; var i = q.Single(); othersplitamt = i.c.ContributionAmount - amt; i.c.ContributionAmount = othersplitamt; DbUtil.Db.SubmitChanges(); bd.BundleSort1 = i.bd.BundleDetailId; } bd.Contribution = new Contribution { CreatedBy = Util.UserId, CreatedDate = bd.CreatedDate, FundId = fund, PeopleId = pid.ToInt2(), ContributionDate = contributiondate ?? Bundle.ContributionDate, ContributionAmount = amt, ContributionStatusId = 0, ContributionTypeId = type, ContributionDesc = notes, CheckNo = (checkno ?? "").Trim().Truncate(20) }; Bundle.BundleDetails.Add(bd); DbUtil.Db.SubmitChanges(); return(ContributionRowData(ctl, bd.ContributionId, othersplitamt)); } catch (Exception ex) { return(new { error = ex.Message }); } }