//Inserts a new Staff Allocation public async Task <IActionResult> OnPostInsertStaffAlloc([FromBody] Models.ActCostSiloAllocation obj) { if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet"))) { try { //Allocation Split is set to per Silo obj.ActCostAllocationSplitID = 12; _context.Add(obj); await _context.SaveChangesAsync(); int id = obj.ActCostSiloAllocationID; // Yes it's here return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Staff Allocation Per Silo Not Added." + d.InnerException.Message)); } } else { return(new JsonResult("Staff Allocation Per Silo Not Inserted")); } }
//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.")); }