public async Task <IActionResult> Edit(int id, [Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { if (id != annualFeeStructure.Year) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(annualFeeStructure); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnnualFeeStructureExists(annualFeeStructure.Year)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(annualFeeStructure)); }
public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { // Throw exception with any error use when they create a new record. // Display the TemData error at the top of the page. // Also keep the variable they input before submit. try { if (ModelState.IsValid) { _context.Add(annualFeeStructure); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { throw new Exception(); } } catch (Exception) { TempData["message"] = "Unable to create a new record."; return(View(annualFeeStructure)); } }
public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { if (ModelState.IsValid) { _context.Add(annualFeeStructure); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(annualFeeStructure)); }
public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { try { if (ModelState.IsValid) { _context.Add(annualFeeStructure); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (Exception ex) { ModelState.AddModelError("", $"Errors to Add New Record:{ex.GetBaseException().Message}"); } return(View(annualFeeStructure)); }
public async Task <IActionResult> Edit(int id, [Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { var latestYear = _context.AnnualFeeStructure .Max(a => a.Year); ////Checks if year selected is not a prior year if (id < latestYear) { TempData["message"] = "Cannot edit a prior year's record"; return(RedirectToAction(nameof(Index))); } if (id != annualFeeStructure.Year) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(annualFeeStructure); await _context.SaveChangesAsync(); TempData["message"] = "Annual Fee " + annualFeeStructure.Year + " was edited"; } catch (DbUpdateConcurrencyException) { if (!AnnualFeeStructureExists(annualFeeStructure.Year)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(annualFeeStructure)); }
public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { if (ModelState.IsValid) { var annualFees = _context.AnnualFeeStructure.Where(x => x.Year == annualFeeStructure.Year).FirstOrDefault(); //Database does not auto increment, cannot allow creation for existing year if (annualFees != null) { TempData["message"] = $"Annual Fee Structure already exists for {annualFeeStructure.Year.ToString()}"; return(RedirectToAction(nameof(Index))); } _context.Add(annualFeeStructure); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(annualFeeStructure)); }
public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { try { if (ModelState.IsValid) { _context.Add(annualFeeStructure); await _context.SaveChangesAsync(); TempData["message"] = "Annual Fee " + annualFeeStructure.Year + " was created"; return(RedirectToAction(nameof(Index))); } return(View(annualFeeStructure)); } catch (Exception ex) { TempData["message"] = "An error ocorred, please try again"; return(View()); } }
public async Task <IActionResult> Edit(int id, [Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { if (id != annualFeeStructure.Year) { return(NotFound()); } if (ModelState.IsValid) { try { //Check the year of the user try to edit. //If user edit the prior year, show and error in TempData and return to Index. if (annualFeeStructure.Year != DateTime.Now.Year) { TempData["message"] = "Cannot edit the record of the prior year"; return(RedirectToAction(nameof(Index))); } else { _context.Update(annualFeeStructure); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!AnnualFeeStructureExists(annualFeeStructure.Year)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(annualFeeStructure)); }
public async Task <IActionResult> Create([Bind("Year,AnnualFee,EarlyDiscountedFee,EarlyDiscountEndDate,RenewDeadlineDate,TaskExemptionFee,SecondBoatFee,ThirdBoatFee,ForthAndSubsequentBoatFee,NonSailFee,NewMember25DiscountDate,NewMember50DiscountDate,NewMember75DiscountDate")] AnnualFeeStructure annualFeeStructure) { if (ModelState.IsValid) { try { // add the record to the database and save the changes _context.Add(annualFeeStructure); await _context.SaveChangesAsync(); // if save was successful, display a message TempData["message"] = $"Record added for year {annualFeeStructure.Year}"; return(RedirectToAction(nameof(Index))); } catch (Exception ex) { // in case of error, user will be returned back to the Create View page, his previous input // preloaded in the fields, and a message describing the error will be displayed ModelState.AddModelError("", $"error while saving annual fee structure: {ex.GetBaseException().Message}"); return(View(annualFeeStructure)); } } return(View(annualFeeStructure)); }
// GET: HMBPAnnualFeeStructure/Create public IActionResult Create() { AnnualFeeStructure annualFee = _context.AnnualFeeStructure.LastOrDefault(); //preload the view with data from the most recent record on file & overlay the year with the current year return(View(annualFee)); }
// GET: JRAnnualFeeStructure/Create public IActionResult Create() { AnnualFeeStructure mt = _context.AnnualFeeStructure.LastOrDefault(); return(View(mt)); }