public ActionResult MaintainDonationType(Donation_Type Donationtype, string button) { if (button == "Save") { try { Donation_Type donation_Type = db.Donation_Type.Find(Donationtype.Donation_Type_ID); if (donation_Type == null) { return(HttpNotFound()); } else { db.Entry(donation_Type).CurrentValues.SetValues(Donationtype); db.SaveChanges(); } } catch (Exception e) { return(RedirectToAction("MaintainDonationType", "Donations")); } } else if (button == "Cancel") { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
public ActionResult MaintainDonationType(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Donation_Type donation_Type = db.Donation_Type.Find(id); if (donation_Type == null) { return(HttpNotFound()); } return(View(donation_Type)); }
public ActionResult AddDonationType(Donation_Type donation_Type, string button) { ViewBag.errorMessage = ""; //Donation_Type asd = new Donation_Type(); if (button == "Save") { try { List <Donation_Type> donationtypes = new List <Donation_Type>(); donationtypes = db.Donation_Type.ToList(); if (donationtypes.Count != 0) { int count = 0; foreach (var item in donationtypes) { if (item.Donation_Type_Name == donation_Type.Donation_Type_Name) { count++; ViewBag.errorMessage = "There is a duplicate Donation Type Already"; return(View()); } } if (count == 0) { db.Donation_Type.Add(donation_Type); db.SaveChanges(); } } else { db.Donation_Type.Add(donation_Type); db.SaveChanges(); } } catch (Exception e) { ViewBag.errorMessage = "There was an Error with network please try again: " + e.Message; return(View()); } } else if (button == "Cancel") { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> UpdateDonation_Type(Donation_Type data) { try { var getData = await con.donation_Types.FindAsync(data.dtId); if (getData != null) { var chkCode = con.donation_Types.Where(c => c.dtCode == data.dtCode && c.dtId != data.dtId).Any(); if (chkCode == false) { getData.dtName = data.dtName; getData.dtCode = data.dtCode; getData.dtStatus = data.dtStatus; con.Entry(getData).State = EntityState.Modified; try { await con.SaveChangesAsync(); return(Ok()); } catch (DbUpdateConcurrencyException) { return(BadRequest(new { message = "An error occured while updating the Info. Please try again later" })); } } else { return(BadRequest(new { message = "This Country code is already exists." })); } } else { return(BadRequest(new { message = "No Record found." })); } } catch (Exception) { return(Content("Data Not added")); } }
public async Task <IActionResult> AddDonation_Type(Donation_Type data) { try { var chkData = await con.donation_Types.Where(c => c.dtCode == data.dtCode).AnyAsync(); if (chkData == true) { return(Content("The code is already exist")); } else { con.donation_Types.Add(data); await con.SaveChangesAsync(); return(Content("")); } } catch (Exception) { return(Content("Data Not added")); } }