public async Task <IHttpActionResult> PostTask(Models.Task task) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } task.DateEnd = task.AddBusinessDay(task.DateStart, task.Workload); db.Tasks.Add(task); await db.SaveChangesAsync(); db.Entry(task).Reference(x => x.Employee).Load(); db.Entry(task).Reference(x => x.ProjectManager).Load(); var dto = new TaskDTO() { Id = task.Id, TaskName = task.TaskName, ProjectManagerName = task.ProjectManager.Name, EmployeeName = task.Employee.Name, DateStart = task.DateStart, Workload = task.Workload, DateEnd = task.DateEnd }; return(CreatedAtRoute("DefaultApi", new { id = task.Id }, dto)); }
public async Task <IHttpActionResult> PostUser(User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Users.Add(user); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = user.Id }, user)); }
public async Task <T> Save(T entity) { await _db.Set <T>().AddAsync(entity); await _db.SaveChangesAsync(); return(entity); }
public async Task <bool> SaveAsync() { return(await _context.SaveChangesAsync() > 0); }