public bool CreateDept(DeptCreate model) { var entity = new Dept() { DeptName = model.DeptName, PersonnelCount = model.PersonnelCount }; using (var ctx = new ApplicationDbContext()) { ctx.DeptDbSet.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Post(DeptCreate dept) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateDeptService(); if (!service.CreateDept(dept)) { return(InternalServerError()); } return(Ok()); }