public async Task <IHttpActionResult> SaveCourse([FromBody] Course model) { if (!ModelState.IsValid) { return(BadRequest()); } db.Courses.Add(model); await db.SaveChangesAsync(); return(Ok(new ResponseMessage <Course> { Result = model })); }
public async Task <IHttpActionResult> SaveStudent([FromBody] Student model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Students.Add(model); await db.SaveChangesAsync(); return(Ok(new ResponseMessage <Student> { Result = model })); }
public async Task Consume(ConsumeContext <CreateDepartmentRequest> context) { var department = new Domain.Department { DepartmentName = context.Message.Name }; await _dbContext.Departments.AddAsync(department); await _dbContext.SaveChangesAsync(); await context.RespondAsync(new CreateDepartmentResponse { Name = context.Message.Name, Id = department.Id }); }
public async Task Consume(ConsumeContext <DeleteDepartmentRequest> context) { var department = _dbContext.Departments.FirstOrDefault(x => x.Id == context.Message.DepartmentId); if (department != null && department.EmployeeCount == 0) { _dbContext.Entry(department).State = EntityState.Deleted; await _dbContext.SaveChangesAsync(); await context.RespondAsync(new DeleteDepartmentResponse { DepartmentId = context.Message.DepartmentId, IsDeleted = true }); } await context.RespondAsync(new DeleteDepartmentResponse { DepartmentId = context.Message.DepartmentId, IsDeleted = false }); }