Esempio n. 1
0
        public async Task <IActionResult> UpdateRegion([FromBody] RegionDto regionDto)
        {
            _log.LogDebug($"REST request to update Region : {regionDto}");
            if (regionDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }

            //TODO catch //DbUpdateConcurrencyException into problem

            Region region = _mapper.Map <Region>(regionDto);

            region.UserId = region.User.Id;
            region.User   = null;
            _applicationDatabaseContext.Update(region);

            /* Force the reference navigation property to be in "modified" state.
             * This allows to modify it with a null value (the field is nullable).
             * This takes into consideration the case of removing the association between the two instances. */
            _applicationDatabaseContext.Entry(region).Reference(region0 => region0.User).IsModified = true;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(region)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, region.Id.ToString())));
        }
Esempio n. 2
0
        public async Task <IActionResult> Update(Person person)
        {
            if (!await _peopleRepository.Exists(x => x.Id == person.Id))
            {
                return(NotFound());
            }

            var result = await _peopleRepository.UpdateAsync(person);

            return(Ok(result)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, result.Id.ToString())));
        }
Esempio n. 3
0
        public async Task <IActionResult> Update(Company company)
        {
            if (!await _companiesRepository.Exists(x => x.Id == company.Id))
            {
                return(NotFound());
            }

            var result = await _companiesRepository.UpdateAsync(company);

            return(Ok(result)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, result.Id.ToString())));
        }
        public async Task <IActionResult> UpdateLocation([FromBody] LocationDto locationDto)
        {
            _log.LogDebug($"REST request to update Location : {locationDto}");
            if (locationDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            Location location = _mapper.Map <Location>(locationDto);
            await _locationService.Save(location);

            return(Ok(location)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, location.Id.ToString())));
        }
Esempio n. 5
0
        public async Task <IActionResult> UpdateDepartment([FromBody] DepartmentDto departmentDto)
        {
            _log.LogDebug($"REST request to update Department : {departmentDto}");
            if (departmentDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            Department department = _mapper.Map <Department>(departmentDto);
            await _departmentService.Save(department);

            return(Ok(department)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, department.Id.ToString())));
        }
        public async Task <IActionResult> UpdateOperation([FromBody] Operation operation)
        {
            _log.LogDebug($"REST request to update Operation : {operation}");
            if (operation.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Entry(operation).State = EntityState.Modified;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(operation).WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, operation.Id.ToString())));
        }
        public async Task <IActionResult> UpdatePieceOfWork([FromBody] PieceOfWorkDto pieceOfWorkDto)
        {
            _log.LogDebug($"REST request to update PieceOfWork : {pieceOfWorkDto}");
            if (pieceOfWorkDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            PieceOfWork pieceOfWork = _mapper.Map <PieceOfWork>(pieceOfWorkDto);
            await _pieceOfWorkService.Save(pieceOfWork);

            return(Ok(pieceOfWork)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, pieceOfWork.Id.ToString())));
        }
Esempio n. 8
0
        public async Task <IActionResult> UpdateJobHistory([FromBody] JobHistoryDto jobHistoryDto)
        {
            _log.LogDebug($"REST request to update JobHistory : {jobHistoryDto}");
            if (jobHistoryDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            JobHistory jobHistory = _mapper.Map <JobHistory>(jobHistoryDto);
            await _jobHistoryService.Save(jobHistory);

            return(Ok(jobHistory)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, jobHistory.Id.ToString())));
        }
        public async Task <IActionResult> UpdateCategoria([FromBody] Categoria categoria)
        {
            _log.LogDebug($"REST request to update Categoria : {categoria}");
            if (categoria.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            await _categoriaRepository.CreateOrUpdateAsync(categoria);

            await _categoriaRepository.SaveChangesAsync();

            return(Ok(categoria)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, categoria.Id.ToString())));
        }
Esempio n. 10
0
        public async Task <IActionResult> UpdatePieceOfWork([FromBody] PieceOfWork pieceOfWork)
        {
            _log.LogDebug($"REST request to update PieceOfWork : {pieceOfWork}");
            if (pieceOfWork.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Update(pieceOfWork);
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(pieceOfWork)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, pieceOfWork.Id.ToString())));
        }
Esempio n. 11
0
        public async Task <IActionResult> UpdateLabel([FromBody] Label label)
        {
            _log.LogDebug($"REST request to update Label : {label}");
            if (label.Id == null)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Entry(label).State = EntityState.Modified;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(label)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, label.Id)));
        }
Esempio n. 12
0
        public async Task <IActionResult> UpdateDeployment([FromBody] Deployment deployment)
        {
            _log.LogDebug($"REST request to update Deployment : {deployment}");
            if (string.IsNullOrEmpty(deployment.Id))
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Update(deployment);
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(deployment)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, deployment.Id.ToString())));
        }
        public async Task <IActionResult> UpdateProduto([FromBody] Produto produto)
        {
            _log.LogDebug($"REST request to update Produto : {produto}");
            if (produto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            await _produtoRepository.CreateOrUpdateAsync(produto);

            await _produtoRepository.SaveChangesAsync();

            return(Ok(produto)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, produto.Id.ToString())));
        }
Esempio n. 14
0
        public async Task <IActionResult> UpdateJob([FromBody] JobDto jobDto)
        {
            _log.LogDebug($"REST request to update Job : {jobDto}");
            if (jobDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            Job job = _mapper.Map <Job>(jobDto);
            await _jobRepository.CreateOrUpdateAsync(job);

            await _jobRepository.SaveChangesAsync();

            return(Ok(job)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, job.Id.ToString())));
        }
Esempio n. 15
0
        public async Task <IActionResult> UpdateEmployee([FromBody] EmployeeDto employeeDto)
        {
            _log.LogDebug($"REST request to update Employee : {employeeDto}");
            if (employeeDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            Employee employee = _mapper.Map <Employee>(employeeDto);
            await _employeeRepository.CreateOrUpdateAsync(employee);

            await _employeeRepository.SaveChangesAsync();

            return(Ok(employee)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, employee.Id.ToString())));
        }
Esempio n. 16
0
        public async Task <IActionResult> UpdateSazeman([FromBody] SazemanDto sazemanDto)
        {
            _log.LogDebug($"REST request to update Sazeman : {sazemanDto}");
            if (sazemanDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }

            //TODO catch //DbUpdateConcurrencyException into problem

            Sazeman sazeman = _mapper.Map <Sazeman>(sazemanDto);
            await _sazemanService.Save(sazeman);

            return(Ok(sazeman)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, sazeman.Id.ToString())));
        }
Esempio n. 17
0
        public async Task <IActionResult> UpdateRegion(long id, [FromBody] Region region)
        {
            _log.LogDebug($"REST request to update Region : {region}");
            if (region.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            if (id != region.Id)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idinvalid");
            }
            await _regionService.Save(region);

            return(Ok(region)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, region.Id.ToString())));
        }
        public async Task <IActionResult> UpdateContact([FromBody] ContactDto contactDto)
        {
            _log.LogDebug($"REST request to update Contact : {contactDto}");
            if (contactDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }

            //TODO catch //DbUpdateConcurrencyException into problem

            Contact contact = _mapper.Map <Contact>(contactDto);
            await _contactService.Save(contact);

            return(Ok(contact)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, contact.Id.ToString())));
        }
Esempio n. 19
0
        public async Task <IActionResult> UpdateJobHistory(long id, [FromBody] JobHistory jobHistory)
        {
            _log.LogDebug($"REST request to update JobHistory : {jobHistory}");
            if (jobHistory.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            if (id != jobHistory.Id)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idinvalid");
            }
            await _jobHistoryService.Save(jobHistory);

            return(Ok(jobHistory)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, jobHistory.Id.ToString())));
        }
Esempio n. 20
0
        public async Task <IActionResult> UpdateDepartment(long id, [FromBody] Department department)
        {
            _log.LogDebug($"REST request to update Department : {department}");
            if (department.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            if (id != department.Id)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idinvalid");
            }
            await _departmentService.Save(department);

            return(Ok(department)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, department.Id.ToString())));
        }
Esempio n. 21
0
        public async Task <IActionResult> UpdateTask(long id, [FromBody] Task task)
        {
            _log.LogDebug($"REST request to update Task : {task}");
            if (task.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            if (id != task.Id)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idinvalid");
            }
            await _taskService.Save(task);

            return(Ok(task)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, task.Id.ToString())));
        }
Esempio n. 22
0
        public async Task <IActionResult> UpdateDepartment([FromBody] Department department)
        {
            _log.LogDebug($"REST request to update Department : {department}");
            if (department.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Update(department);

            /* Force the reference navigation property to be in "modified" state.
             * This allows to modify it with a null value (the field is nullable).
             * This takes into consideration the case of removing the association between the two instances. */
            _applicationDatabaseContext.Entry(department).Reference(department0 => department0.Location).IsModified = true;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(department)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, department.Id.ToString())));
        }