public async Task <IActionResult> Register([FromBody] RegisterAccountRequest registerAccount) { var user = new Employee { UserName = registerAccount.Email, Email = registerAccount.Email, FirstName = registerAccount.FirstName, LastName = registerAccount.LastName, }; if (registerAccount.ProfilePhoto != null) { user.ProfilePhoto = registerAccount.ProfilePhoto; } if (registerAccount.RegisteredOfficeId != 0) { user.RegisteredOffice = await _officeRepository.FindById(registerAccount.RegisteredOfficeId); } var result = await _userManager.CreateAsync(user, registerAccount.Password); if (!result.Succeeded) { return(Conflict()); } return(Ok(DateTime.Now)); }
public async Task <ActionResult <Travel> > CreateTravel([FromBody] CreateTravelRequest request) { try { var travel = new Travel { Name = request.Name, TravelTo = await _officeRepository.FindById(request.TravelToId), TravelFrom = await _officeRepository.FindById(request.TravelFromId), StartTime = request.StartTime, EndTime = request.EndTime, Hotels = request.Hotels, Transports = request.Transports, Cost = request.Cost, OrganizedBy = await _employeeRepository.FindById(request.OrganizedById) }; return(Ok(await _travelRepository.Create(travel))); } catch (ArgumentException e) { return(Conflict(e.Message)); } }
public async Task <ActionResult <Travel> > CreateEmployeeTravel([FromBody] CreateEmployeeTravelRequest request) { try { if (!await _employeeTravelRepository.CheckTravelsByEmployeeId(request.EmployeeId, request.TravelId)) { return(Conflict(" This employee already has this trip ")); } var employeeTravel = new EmployeeTravel { Employee = await _employeeRepository.FindById(request.EmployeeId), Travel = await _travelRepository.FindByIdWithOrganizedBy(request.TravelId), Confirm = request.Confirm, }; if (request.NeedApartment) { var _employeeTravel = await _employeeTravelRepository.Create(employeeTravel); var _office = await _officeRepository.FindById(_employeeTravel.Travel.TravelTo.Id); await _apartmentRepository.AddGuest(await _apartmentRepository.FindById(_office.OfficeApartment.Id), _employeeTravel); return(Ok()); } else { return(Ok(await _employeeTravelRepository.Create(employeeTravel))); } } catch (ArgumentException e) { return(Conflict(e.Message)); } }
public async Task <ActionResult <Office> > GetById(int id) { return(Ok(await _officeRepository.FindById(id))); }