public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR")) { try { _context.Attach((CicotiWebApp.Models.JobDescription)JobDescription).State = EntityState.Modified; 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 <JsonResult> OnPutUpdate([FromBody] List <InvoiceStatus> InvoiceListing) { int NewInvoiceStatusID = 0; string InvoiceNotAdded = "WorkFlow Sequence Error: Invoices Not Added: "; int InvProcessedCount = 0; int InvNotProcessedCount = 0; if (InvoiceListing != null && InvoiceListing.Count() > 0) { NewInvoiceStatusID = InvoiceListing.First().StatusID; //First Check if this user can update the Invoice to this Status if (await workFlowRule.WorkFlowRuleRole(NewInvoiceStatusID, HttpContext)) { try { var UserId = _userManager.GetUserId(HttpContext.User); CicotiWebApp.Models.Invoice InvoiceItem; //Update the Invoice Table in Database foreach (var In in InvoiceListing) { InvoiceItem = _context.Invoices.FirstOrDefault(i => i.InvoiceID == In.InvoiceID); if (workFlowRule.WorFlowRuleSequence(In.StatusID, InvoiceItem.StatusID)) { In.UserID = UserId; InvoiceItem.StatusID = In.StatusID; _context.Attach(InvoiceItem).State = EntityState.Modified; _context.Add(In); await _context.SaveChangesAsync(); InvProcessedCount += InvProcessedCount + 1; } else { InvNotProcessedCount += InvNotProcessedCount + 1; InvoiceNotAdded += InvoiceItem.InvoiceNumber + "; "; } } if (InvNotProcessedCount == 0) { return(new JsonResult("Success: No of Invoices Processed: " + InvProcessedCount)); } else { return(new JsonResult("No of Invoices Processed Successfully: " + InvProcessedCount + " . " + "No of Invoices Not Processed: " + InvNotProcessedCount + "; " + InvoiceNotAdded)); } } catch (DbUpdateException d) { return(new JsonResult("Invoice Status not Updated. " + d.InnerException.Message)); } } else { return(new JsonResult("Invoice Status not Updated. You do not have rights to update to this Invoice Status.")); } }//Nothing has been selected for updating return(new JsonResult("You have not selected Deliveries / Invoices for Updating")); }
public IActionResult OnPutUpdate([FromBody] Location obj) { if (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin"))) { _context.Attach(obj).State = EntityState.Modified; _context.SaveChanges(); return(new JsonResult("Location: " + obj.LocationName + " Changes are saved.")); } return(new JsonResult("You do not have access to add new Locations")); }
//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")); }
//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 SalesLink Details public async Task <IActionResult> OnPutUpdateRepEmployeeLink([FromBody] SalesRepCodeEmployeeNoLink obj) { if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR"))) { try { _context.Attach(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Rep Employee Changes not saved." + d.InnerException.Message)); } } return(new JsonResult("Rep Employee not saved. You do not have access rights to save these changes")); }
//Updates the existing Driver Details public async Task <IActionResult> OnPutUpdateDriver([FromBody] Models.Driver 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("Driver Changes not saved." + d.InnerException.Message)); } } return(new JsonResult("Drivers Changes not saved. You do not have access rights to save these changes")); }
//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.")); }
//Updates the existing Staff Allocation Details public async Task <IActionResult> OnPutUpdateStaffAlloc([FromBody] Models.ActCostSiloAllocation obj) { if (obj != null && (HttpContext.User.IsInRole("Admin"))) { try { //Set the split to be per SILO obj.ActCostAllocationSplitID = 12; _context.Attach(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Staff Alocation not saved." + d.InnerException.Message)); } } return(new JsonResult("Staff Allocation saved.")); }
//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> OnPutUpdate([FromBody] Destination obj) { if (HttpContext.User.IsInRole("Fleet") || (HttpContext.User.IsInRole("Admin"))) { try { _context.Attach(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new JsonResult("Destination updated.")); } catch (DbUpdateException d) { return(new JsonResult("Destination not update." + d.InnerException.Message)); } } else { return(new JsonResult("You do not have rights to Update this Destination")); } }
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("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")); }