public void AddNewDepartmentalFunction(int deptId, DepartmentalFunction newDepartmentalFunction) { var selectedDepartment = (from d in _repo.Query <Department>().Include(d => d.DepartmentalFunctions) where d.Id == deptId select d).FirstOrDefault(); var deparmentalFunction = new DepartmentalFunction() { DepartFuncName = newDepartmentalFunction.DepartFuncName, DepartFuncDesc = newDepartmentalFunction.DepartFuncDesc, MissionCritical = newDepartmentalFunction.MissionCritical }; selectedDepartment.DepartmentalFunctions.Add(deparmentalFunction); _repo.Update(selectedDepartment); }
public IActionResult Post(int deptId, [FromBody] DepartmentalFunction newDepartmentalFunction) { if (!ModelState.IsValid) { return(BadRequest(this.ModelState)); } if (newDepartmentalFunction.DepartFuncName == "") { return(NotFound()); } else { _departmentalFunctionsService.UpdateDepartmentalFunction(deptId, newDepartmentalFunction); return(Ok(newDepartmentalFunction)); } }
public void UpdateDepartmentalFunction(int deptFuncId, DepartmentalFunction selectedDepartmentalFunction) { var departmentalFunctionToUpdate = (from df in _repo.Query <DepartmentalFunction>() where df.Id == deptFuncId select new DepartmentalFunction() { Id = df.Id, DepartFuncName = df.DepartFuncName, DepartFuncDesc = df.DepartFuncDesc, MissionCritical = df.MissionCritical }).FirstOrDefault(); departmentalFunctionToUpdate.DepartFuncName = selectedDepartmentalFunction.DepartFuncName; departmentalFunctionToUpdate.DepartFuncDesc = selectedDepartmentalFunction.DepartFuncDesc; _repo.Update(departmentalFunctionToUpdate); _repo.SaveChanges(); }