public HttpResponseMessage AddDepartment(Department DepartmentObj) { try { return Request.CreateResponse(HttpStatusCode.Created, _repo.AddDepartment(DepartmentObj)); } catch (Exception) { throw; } }
public Department AddDepartment(Department DepartmentObj) { try { Department dp = _context.Departments.Where(x => x.Name == DepartmentObj.Name).FirstOrDefault(); if (dp == null) { dp.CreatedDate = DateTime.Now; dp.ModifiedDate = DateTime.Now; _context.Departments.Add(DepartmentObj); _context.SaveChangesAsync(); return dp; } return null; } catch (Exception) { throw; } }
public bool UpdateDepartment(Department DepartmentObj) { try { Department dp = _context.Departments.Where(x => x.DepartmentId == DepartmentObj.DepartmentId).FirstOrDefault(); if (dp != null) { dp.Name = DepartmentObj.Name; dp.ModifiedDate = DateTime.Now; _context.Entry(dp).State = System.Data.Entity.EntityState.Modified; _context.SaveChangesAsync(); return true; } return false; } catch (Exception) { throw; } }