public async Task <IActionResult> Donation(string id) { var user = await _userManager.GetUserAsync(User); if (User == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } TXTDonationDetailView obj = new TXTDonationDetailView(); if (id == null) { ViewData["_Save"] = "True"; ViewData["_Update"] = "False"; obj.lstDonor = db.TxsdonorDetail.ToList(); obj.lstCategory = db.TxsdonationCategoryDetail.ToList(); obj.master.DnnActive = (obj.master.DnnActive == null) ? true : false; obj.master.DnnTaxable = (obj.master.DnnTaxable == null) ? false : true; return(PartialView(obj)); } else { ViewData["_Save"] = "False"; ViewData["_Update"] = "True"; obj.master = db.TxtdonationDetail.Where(x => x.Id == user.Id && x.UserName == user.UserName && x.DnnId == Convert.ToInt32(id)).FirstOrDefault(); obj.lstDonor = db.TxsdonorDetail.Where(x => x.DnrId == obj.master.DnnDnrId).ToList(); obj.lstCategory = db.TxsdonationCategoryDetail.Where(x => x.DcaId == obj.master.DnnDcaId).ToList(); obj.master.DnnActive = (obj.master.DnnActive == true) ? true : false; obj.master.DnnTaxable = (obj.master.DnnTaxable == true) ? true : false; return(PartialView(obj)); } }
public async Task <IActionResult> Donation(TXTDonationDetailView obj, string DnnActive, string DnnTaxable, string Save, string Update) { var user = await _userManager.GetUserAsync(User); if (User == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } if (Save != null) { obj.master.Id = user.Id; obj.master.UserName = user.UserName; obj.master.DnnActive = (DnnActive == "true") ? true : false; obj.master.DnnTaxable = (DnnTaxable == "true") ? true : false; obj.master.EnterBy = user.UserName; obj.master.EnterDate = System.DateTime.Now; db.TxtdonationDetail.Add(obj.master); db.SaveChanges(); } if (Update != null) { TxtdonationDetail obj1 = new TxtdonationDetail(); obj1 = db.TxtdonationDetail.Where(x => x.Id == user.Id && x.UserName == user.UserName && x.DnnId == obj.master.DnnId).FirstOrDefault(); if (obj1 != null) { obj1.DnnDnrId = obj.master.DnnDnrId; obj1.DnnAmount = obj.master.DnnAmount; obj1.DnnType = obj.master.DnnType; obj1.DnnChequeNo = obj.master.DnnChequeNo; obj1.DnnDate = obj.master.DnnDate; obj1.DnnDcaId = obj.master.DnnDcaId; obj1.DnnDesc = obj.master.DnnDesc; obj1.DnnActive = (DnnActive == "true") ? true : false; obj1.DnnTaxable = (DnnTaxable == "true") ? true : false; obj1.EditBy = user.UserName; obj1.EditDate = System.DateTime.Now; db.SaveChanges(); } } return(RedirectToAction("showDonation")); }