public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.ActCostSiloAllocations.Add(ActCostSiloAllocation); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.ActCostAccountAmtPrinciple.Add(AccAmtPrinciple); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin"))) { var ProvinceToUpdate = await _context.Provinces.FindAsync(id); if (await TryUpdateModelAsync( ProvinceToUpdate, "Province", p => p.ProvinceID, p => p.CountryID, p => p.ProvinceName )) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } } //Select Country ID if TryUpdateSync Fails PopulateCountryDropDownList(_context, id); return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR")) { try { _context.JobDescription.Add(JobDescription); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JobDescriptionExists(JobDescription.JobDescriptionID)) { return(NotFound()); } else { throw; } } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Admin")) { try { _context.Attach((ExchangeRate)ExchangeRate).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExchangeRateExists(ExchangeRate.ExchangeRateID)) { return(NotFound()); } else { throw; } } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")) { try { Vehicle.RegNumberABB = Vehicle.RegNumberABB.ToString().Replace(" ", "").Trim(); //set this as a delivery vehicle Vehicle.VehiclePurposeID = 2; _context.Attach(Vehicle).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VehicleExists(Vehicle.VehicleID)) { return(NotFound()); } else { throw; } } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var EmptyProvince = new Models.Province(); if (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin"))) { if (await TryUpdateModelAsync( EmptyProvince, "Province", p => p.ProvinceID, p => p.CountryID, p => p.ProvinceName )) { _context.Provinces.Add(EmptyProvince); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } //Select Country ID if TryUpdateSync Fails PopulateCountryDropDownList(_context, EmptyProvince.CountryID); return(Page()); } return(new JsonResult("You do not have access to update this screen")); }
//Updates the existing Account Details public async Task <IActionResult> OnPutUpdateAccount([FromBody] Models.ActCostAccount obj) { if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet"))) { try { _context.Attach(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Account Changes not saved." + d.InnerException.Message)); } } return(new JsonResult("Account Changes not saved.")); }
public async Task <IActionResult> OnDeleteDelete([FromBody] CicotiWebApp.Models.SKU obj) { if (obj != null && HttpContext.User.IsInRole("Admin")) { try { _context.SKUs.Remove(obj); await _context.SaveChangesAsync(); return(new JsonResult("SKU removed successfully")); } catch (DbUpdateException d) { return(new JsonResult("SKU not removed." + d.InnerException.Message)); } } else { return(new JsonResult("SKU not removed.")); } }
//Updates the existing Vehicle public async Task <IActionResult> OnPutUpdateVehicle([FromBody] Vehicle obj) { if (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")) { try { obj.RegNumberABB = obj.RegistrationNumber.ToString().Replace(" ", "").Trim(); obj.SubContractorID = 2; obj.ActCostAllocationSplitID = _vehicleBusLayer.FindAllocationSplitID(obj.CostCentreID); _context.Attach(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Vehicle Changes not saved." + d.InnerException.Message)); } } return(new JsonResult("You do not have access to these changes")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Admin")) { _context.ExchangeRates.Add((ExchangeRate)ExchangeRate); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")) { _context.SubContractor.Add(SubContractor); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostInsert([FromBody] Destination obj) { if (obj != null && (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin")))) { try { _context.Add(obj); await _context.SaveChangesAsync(); return(new JsonResult("Destination has been created successfully.")); } catch (DbUpdateException d) { return(new JsonResult("New Destination not created." + d.InnerException.Message)); } } else { return(new JsonResult("Insert Destination was null")); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("HR") || (HttpContext.User.IsInRole("Admin"))) { try { _context.SalesRepCodeEmployeeNoLink.Add(SalesRepEmployLink); await _context.SaveChangesAsync(); return(new JsonResult("SalesRepEmployeeLink has been created successfully.")); } catch (DbUpdateException d) { return(new JsonResult("SalesRepEmployeeLink not created." + d.InnerException.Message)); } } return(RedirectToPage("./Listing")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin"))) { try { _context.Drivers.Add(Driver); await _context.SaveChangesAsync(); return(new JsonResult("Driver has been created successfully.")); } catch (DbUpdateException d) { return(new JsonResult("Driver not created." + d.InnerException.Message)); } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { //if (!ModelState.IsValid) //{ // return Page(); //} if (HttpContext.User.IsInRole("Manager") || (HttpContext.User.IsInRole("Admin"))) { try { if (SkuUomLink.SkuUomLinkID == 0) { _context.SkuUomLinks.Add(SkuUomLink); await _context.SaveChangesAsync(); } else { _context.Attach((CicotiWebApp.Models.SkuUomLink)SkuUomLink).State = EntityState.Modified; await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!SKULinkExists(SkuUomLink.SkuUomLinkID)) { return(NotFound()); } else { throw; } } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if ((HttpContext.User.IsInRole("Admin"))) { try { if (Principal.PrincipleID == 0) { _context.Principle.Add(Principal); await _context.SaveChangesAsync(); } else { _context.Attach((CicotiWebApp.Models.Principle)Principal).State = EntityState.Modified; await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!PrincipalExists(Principal.PrincipleID)) { return(NotFound()); } else { throw; } } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet")) { Vehicle.RegNumberABB = Vehicle.RegistrationNumber.ToString().Replace(" ", "").Trim(); Vehicle.VehiclePurposeID = 2; _context.Vehicles.Add(Vehicle); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
//Inserts a new Employee with details public async Task <IActionResult> OnPostInsertEmployee([FromBody] Models.Employee obj) { if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR"))) { try { obj.ActCostAllocationSplitID = _empBusLayer.FindAllocationSplitID(obj.CostCentreID, obj.DepartmentID); if (obj.EmployeeID == 0) { _context.Add(obj); } else { _context.Attach(obj).State = EntityState.Modified; } await _context.SaveChangesAsync(); var value = new { msg = "Employee Successfully Updated", employee = obj }; return(new JsonResult(value)); } catch (DbUpdateException d) { var value = new { msg = "Employee Changes not Saved" + d.InnerException.Message, employee = obj }; return(new JsonResult(value)); } } else { var value = new { msg = "Employee Changes not Saved", employee = obj }; return(new JsonResult(value)); } }
//Updates the existing Load Header public async Task <IActionResult> OnPutUpdateLoad([FromBody] Load obj) { //First Check if you have the rights to update this load if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet"))) { try { //check if all Invoices have a POD Status before the Load can be changed to Status Complete //if any invoice does not have an Invoice Status of POD then the Load Cannot be marked as Complete if (obj.LoadStatusID == 2) { if (!CheckInvoiceStatus(obj)) { //Reset the Load Status to Incomplete if it fails the Invoice POD Test; obj.LoadStatusID = 1; return(new JsonResult("Load not saved as Complete as there are still invoices which do not have a POD.")); } } _context.Attach(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); //if the Status of the Load has been changed to Cancelled and the previous //status was not cancelled then revert all the invoices to their previous status if (obj.LoadStatusID == 3) { await CancelLoad(obj.LoadID); } return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Load Changes not saved." + d.InnerException.Message)); } } return(new JsonResult("You do not have access righst to change this load")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin"))) { try { _context.Countries.Add(Country); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException d) { return(new JsonResult(d.InnerException.Message)); } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnDeleteDelete([FromBody] ActCostAccountAmtPrinciple obj) { if (obj != null && HttpContext.User.IsInRole("Admin")) { try { _context.ActCostAccountAmtPrinciple.Remove(obj); await _context.SaveChangesAsync(); return(new JsonResult("Other Income Removed successfully")); } catch (DbUpdateException d) { return(new JsonResult("Other Income Amount not removed." + d.InnerException.Message)); } } else { return(new JsonResult("Other Income not removed.")); } }
public async Task <IActionResult> OnDeleteDelete([FromBody] SalesRepCodeEmployeeNoLink obj) { if (obj != null && HttpContext.User.IsInRole("Admin")) { try { _context.SalesRepCodeEmployeeNoLink.Remove(obj); await _context.SaveChangesAsync(); return(new JsonResult("SalesRepEmployeeLink removed successfully")); } catch (DbUpdateException d) { return(new JsonResult("SalesRepEmployeeLink not removed." + d.InnerException.Message)); } } else { return(new JsonResult("SalesRepEmployeeLink not removed.")); } }
public async Task <IActionResult> OnDeleteDelete([FromBody] CicotiWebApp.Models.CustomerAccountLocationLink obj) { if (obj != null && HttpContext.User.IsInRole("Fleet") || HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Manager")) { try { _context.CustomerAccountLocationLink.Remove(obj); await _context.SaveChangesAsync(); return(new JsonResult("Customer Location Item removed successfully")); } catch (DbUpdateException d) { return(new JsonResult("Customer Location removed." + d.InnerException.Message)); } } else { return(new JsonResult("Customer Location not removed.")); } }
public async Task <IActionResult> OnDeleteDelete([FromBody] ActCostSiloAllocation obj) { if (obj != null && HttpContext.User.IsInRole("Admin")) { try { _context.ActCostSiloAllocations.Remove(obj); await _context.SaveChangesAsync(); return(new JsonResult("Silo Removed successfully")); } catch (DbUpdateException d) { return(new JsonResult("Silo Allocation not removed." + d.InnerException.Message)); } } else { return(new JsonResult("Silo Allocation not removed.")); } }
public async Task <IActionResult> OnDeleteDelete([FromBody] UserItem obj) { if (obj != null && HttpContext.User.IsInRole("Admin")) { try { ApplicationUser user = _context.Users.FirstOrDefault(u => u.Id == obj.UserID); var identityUserRole = _context.UserRoles.FirstOrDefault( u => u.UserId == obj.UserID && u.RoleId == obj.RoleID); _context.UserRoles.Remove(identityUserRole); await _context.SaveChangesAsync(); return(new JsonResult("User Role removed successfully")); } catch (DbUpdateException d) { return(new JsonResult("User Role not removed." + d.InnerException.Message)); } } else { return(new JsonResult("Vehicle not removed.")); } }