public async Task <IActionResult> Create(Company company) { var result = await _companiesRepository.SaveAsync(company); return(CreatedAtAction(nameof(GetCompany), new { id = result.Id }, result) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, result.Id.ToString()))); }
public async Task <IActionResult> Create(Person person) { var result = await _peopleRepository.SaveAsync(person); return(CreatedAtAction(nameof(GetPerson), new { id = result.Id }, result) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, result.Id.ToString()))); }
public async Task <ActionResult <User> > CreateUser([FromBody] UserDto userDto) { _log.LogDebug($"REST request to save User : {userDto}"); if (userDto.Id != null) { throw new BadRequestAlertException("A new user cannot already have an ID", "userManagement", "idexists"); } // Lowercase the user login before comparing with database if (await _userManager.FindByNameAsync(userDto.Login.ToLowerInvariant()) != null) { throw new LoginAlreadyUsedException(); } if (await _userManager.FindByEmailAsync(userDto.Email.ToLowerInvariant()) != null) { throw new EmailAlreadyUsedException(); } var newUser = await _userService.CreateUser(userDto); await _mailService.SendCreationEmail(newUser); return(CreatedAtAction(nameof(GetUser), new { login = newUser.Login }, newUser) .WithHeaders(HeaderUtil.CreateEntityCreationAlert("userManagement.created", newUser.Login))); }
public async Task <ActionResult <Task> > CreateTask([FromBody] Task task) { _log.LogDebug($"REST request to save Task : {task}"); if (task.Id != 0) { throw new BadRequestAlertException("A new task cannot already have an ID", EntityName, "idexists"); } await _taskService.Save(task); return(CreatedAtAction(nameof(GetTask), new { id = task.Id }, task) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, task.Id.ToString()))); }
public async Task <ActionResult <Country> > CreateCountry([FromBody] Country country) { _log.LogDebug($"REST request to save Country : {country}"); if (country.Id != 0) { throw new BadRequestAlertException("A new country cannot already have an ID", EntityName, "idexists"); } await _countryService.Save(country); return(CreatedAtAction(nameof(GetCountry), new { id = country.Id }, country) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, country.Id.ToString()))); }
public async Task <ActionResult <Project> > CreateProject([FromBody] Project project) { _log.LogDebug($"REST request to save Project : {project}"); if (string.IsNullOrEmpty(project?.Id)) { throw new BadRequestAlertException("A new project cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.Projects.Add(project); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetProject), new { id = project.Id }, project) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, project.Id.ToString()))); }
public async Task <ActionResult <ConfigController> > CreateConfig([FromBody] Config config) { _log.LogDebug($"REST request to save Config : {config}"); if (string.IsNullOrEmpty(config.Id)) { throw new BadRequestAlertException("A new config cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.Configs.Add(config); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetConfig), new { id = config.Id }, config) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, config.Id))); }
public async Task <ActionResult <Region> > CreateRegion([FromBody] Region region) { _log.LogDebug($"REST request to save Region : {region}"); if (region.Id != 0) { throw new BadRequestAlertException("A new region cannot already have an ID", EntityName, "idexists"); } await _regionService.Save(region); return(CreatedAtAction(nameof(GetRegion), new { id = region.Id }, region) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, region.Id.ToString()))); }
public async Task <ActionResult <Department> > CreateDepartment([FromBody] Department department) { _log.LogDebug($"REST request to save Department : {department}"); if (department.Id != 0) { throw new BadRequestAlertException("A new department cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.AddGraph(department); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetDepartment), new { id = department.Id }, department) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, department.Id.ToString()))); }
public async Task <ActionResult <PieceOfWork> > CreatePieceOfWork([FromBody] PieceOfWork pieceOfWork) { _log.LogDebug($"REST request to save PieceOfWork : {pieceOfWork}"); if (pieceOfWork.Id != 0) { throw new BadRequestAlertException("A new pieceOfWork cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.AddGraph(pieceOfWork); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetPieceOfWork), new { id = pieceOfWork.Id }, pieceOfWork) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, pieceOfWork.Id.ToString()))); }
public async Task <ActionResult <Employee> > CreateEmployee([FromBody] Employee employee) { _log.LogDebug($"REST request to save Employee : {employee}"); if (employee.Id != 0) { throw new BadRequestAlertException("A new employee cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.AddGraph(employee); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetEmployee), new { id = employee.Id }, employee) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, employee.Id.ToString()))); }
public async Task <ActionResult <Environment> > CreateEnvironment([FromBody] Environment environment) { _log.LogDebug($"REST request to save Environment : {environment}"); if (string.IsNullOrEmpty(environment.Id)) { throw new BadRequestAlertException("A new environment cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.Environments.Add(environment); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetEnvironment), new { id = environment.Id }, environment) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, environment.Id))); }
public async Task <ActionResult <Operation> > CreateOperation([FromBody] Operation operation) { _log.LogDebug($"REST request to save Operation : {operation}"); if (operation.Id != 0) { throw new BadRequestAlertException("A new operation cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.AddGraph(operation); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetOperation), new { id = operation.Id }, operation) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, operation.Id.ToString()))); }
public async Task <ActionResult <Release> > CreateRelease([FromBody] Release release) { _log.LogDebug($"REST request to save Release : {release}"); if (string.IsNullOrEmpty(release.Id)) { throw new BadRequestAlertException("A new release cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.Releases.Add(release); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetRelease), new { id = release.Id }, release) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, release.Id.ToString()))); }
public async Task <ActionResult <JobHistory> > CreateJobHistory([FromBody] JobHistory jobHistory) { _log.LogDebug($"REST request to save JobHistory : {jobHistory}"); if (jobHistory.Id != 0) { throw new BadRequestAlertException("A new jobHistory cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.AddGraph(jobHistory); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetJobHistory), new { id = jobHistory.Id }, jobHistory) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, jobHistory.Id.ToString()))); }
public async Task <ActionResult <Label> > CreateLabel([FromBody] Label label) { _log.LogDebug($"REST request to save Label : {label}"); if (label.Id != 0) { throw new BadRequestAlertException("A new label cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.Labels.Add(label); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetLabel), new { id = label.Id }, label) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, label.Id.ToString()))); }
public async Task <ActionResult <Deployment> > CreateDeployment([FromBody] Deployment deployment) { _log.LogDebug($"REST request to save Deployment : {deployment}"); if (string.IsNullOrEmpty(deployment.Id)) { throw new BadRequestAlertException("A new deployment cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.Deployments.Add(deployment); await _applicationDatabaseContext.SaveChangesAsync(); _releaseCleanupService.PerformCleanup(deployment); return(CreatedAtAction(nameof(GetDeployment), new { id = deployment.Id }, deployment) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, deployment.Id))); }
public async Task <ActionResult <SazemanDto> > CreateSazeman([FromBody] SazemanDto sazemanDto) { _log.LogDebug($"REST request to save Sazeman : {sazemanDto}"); if (sazemanDto.Id != 0) { throw new BadRequestAlertException("A new sazeman cannot already have an ID", EntityName, "idexists"); } Sazeman sazeman = _mapper.Map <Sazeman>(sazemanDto); await _sazemanService.Save(sazeman); return(CreatedAtAction(nameof(GetSazeman), new { id = sazeman.Id }, sazeman) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, sazeman.Id.ToString()))); }
public async Task <ActionResult <PieceOfWorkDto> > CreatePieceOfWork([FromBody] PieceOfWorkDto pieceOfWorkDto) { _log.LogDebug($"REST request to save PieceOfWork : {pieceOfWorkDto}"); if (pieceOfWorkDto.Id != 0) { throw new BadRequestAlertException("A new pieceOfWork cannot already have an ID", EntityName, "idexists"); } PieceOfWork pieceOfWork = _mapper.Map <PieceOfWork>(pieceOfWorkDto); await _pieceOfWorkService.Save(pieceOfWork); return(CreatedAtAction(nameof(GetPieceOfWork), new { id = pieceOfWork.Id }, pieceOfWork) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, pieceOfWork.Id.ToString()))); }
public async Task <ActionResult <ContactDto> > CreateContact([FromBody] ContactDto contactDto) { _log.LogDebug($"REST request to save Contact : {contactDto}"); if (contactDto.Id != 0) { throw new BadRequestAlertException("A new contact cannot already have an ID", EntityName, "idexists"); } Contact contact = _mapper.Map <Contact>(contactDto); await _contactService.Save(contact); return(CreatedAtAction(nameof(GetContact), new { id = contact.Id }, contact) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, contact.Id.ToString()))); }
public async Task <ActionResult <JobHistoryDto> > CreateJobHistory([FromBody] JobHistoryDto jobHistoryDto) { _log.LogDebug($"REST request to save JobHistory : {jobHistoryDto}"); if (jobHistoryDto.Id != 0) { throw new BadRequestAlertException("A new jobHistory cannot already have an ID", EntityName, "idexists"); } JobHistory jobHistory = _mapper.Map <JobHistory>(jobHistoryDto); await _jobHistoryService.Save(jobHistory); return(CreatedAtAction(nameof(GetJobHistory), new { id = jobHistory.Id }, jobHistory) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, jobHistory.Id.ToString()))); }
public async Task <ActionResult <DepartmentDto> > CreateDepartment([FromBody] DepartmentDto departmentDto) { _log.LogDebug($"REST request to save Department : {departmentDto}"); if (departmentDto.Id != 0) { throw new BadRequestAlertException("A new department cannot already have an ID", EntityName, "idexists"); } Department department = _mapper.Map <Department>(departmentDto); await _departmentService.Save(department); return(CreatedAtAction(nameof(GetDepartment), new { id = department.Id }, department) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, department.Id.ToString()))); }
public async Task <ActionResult <LocationDto> > CreateLocation([FromBody] LocationDto locationDto) { _log.LogDebug($"REST request to save Location : {locationDto}"); if (locationDto.Id != 0) { throw new BadRequestAlertException("A new location cannot already have an ID", EntityName, "idexists"); } Location location = _mapper.Map <Location>(locationDto); await _locationService.Save(location); return(CreatedAtAction(nameof(GetLocation), new { id = location.Id }, location) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, location.Id.ToString()))); }
public async Task <ActionResult <Job> > CreateJob([FromBody] Job job) { _log.LogDebug($"REST request to save Job : {job}"); if (job.Id != 0) { throw new BadRequestAlertException("A new job cannot already have an ID", EntityName, "idexists"); } await _jobRepository.CreateOrUpdateAsync(job); await _jobRepository.SaveChangesAsync(); return(CreatedAtAction(nameof(GetJob), new { id = job.Id }, job) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, job.Id.ToString()))); }
public async Task <ActionResult <Produto> > CreateProduto([FromBody] Produto produto) { _log.LogDebug($"REST request to save Produto : {produto}"); if (produto.Id != 0) { throw new BadRequestAlertException("A new produto cannot already have an ID", EntityName, "idexists"); } await _produtoRepository.CreateOrUpdateAsync(produto); await _produtoRepository.SaveChangesAsync(); return(CreatedAtAction(nameof(GetProduto), new { id = produto.Id }, produto) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, produto.Id.ToString()))); }
public async Task <ActionResult <Categoria> > CreateCategoria([FromBody] Categoria categoria) { _log.LogDebug($"REST request to save Categoria : {categoria}"); if (categoria.Id != 0) { throw new BadRequestAlertException("A new categoria cannot already have an ID", EntityName, "idexists"); } await _categoriaRepository.CreateOrUpdateAsync(categoria); await _categoriaRepository.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCategoria), new { id = categoria.Id }, categoria) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, categoria.Id.ToString()))); }
public async Task <ActionResult <BankAccount> > CreateBankAccount([FromBody] BankAccount bankAccount) { _log.LogDebug($"REST request to save BankAccount : {bankAccount}"); if (bankAccount.Id != null) { throw new BadRequestAlertException("A new bankAccount cannot already have an ID", EntityName, "idexists"); } _applicationDatabaseContext.BankAccounts.Add(bankAccount); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetBankAccount), new { id = bankAccount.Id }, bankAccount) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, bankAccount.Id))); }
public async Task <ActionResult <EmployeeDto> > CreateEmployee([FromBody] EmployeeDto employeeDto) { _log.LogDebug($"REST request to save Employee : {employeeDto}"); if (employeeDto.Id != 0) { throw new BadRequestAlertException("A new employee cannot already have an ID", EntityName, "idexists"); } Employee employee = _mapper.Map <Employee>(employeeDto); await _employeeRepository.CreateOrUpdateAsync(employee); await _employeeRepository.SaveChangesAsync(); return(CreatedAtAction(nameof(GetEmployee), new { id = employee.Id }, employee) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, employee.Id.ToString()))); }
public async Task <ActionResult <RegionDto> > CreateRegion([FromBody] RegionDto regionDto) { _log.LogDebug($"REST request to save Region : {regionDto}"); if (regionDto.Id != 0) { throw new BadRequestAlertException("A new region cannot already have an ID", EntityName, "idexists"); } Region region = _mapper.Map <Region>(regionDto); region.User = null; _applicationDatabaseContext.AddGraph(region); await _applicationDatabaseContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetRegion), new { id = region.Id }, region) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, region.Id.ToString()))); }