public async Task <GarageResponseModel> CreateGarage(GarageCreateRequestModel model, string userId) { var departmet = new Department() { Name = "Valet Bay", }; var newEmployee = new Employee() { Name = model.AdminName, Role = GarageRoleType.Admin, UserId = userId, }; var newOrg = new Garage() { Name = model.GarageName }; departmet.Employees.Add(newEmployee); newOrg.Employees.Add(newEmployee); newOrg.Departments.Add(departmet); this.dbContext.Add(newOrg); await this.dbContext.SaveChangesAsync(); return(new GarageResponseModel() { Id = newOrg.Id, Departments = newOrg.Departments.Select(x => new DepartmentListResponseModel() { Id = x.Id, Name = x.Name }).ToList(), Employees = newOrg.Employees.Select(x => new EmployeeResponseModel() { EmployeeId = x.Id, Name = x.Name, Role = (int)x.Role, RoleDisplayName = x.Role.ToString() }).ToList(), GarageName = newOrg.Name, }); }
public async Task <ActionResult <GarageResponseModel> > Create(GarageCreateRequestModel model) { return(await this.garageService.CreateGarage(model, this.currentUserService.UserId)); }