Beispiel #1
0
        public async Task <IActionResult> PutProjects(decimal id, ProjectDto projectDto)
        {
            Project project = new Project {
                NProject    = projectDto.IdProject,
                IdDep       = projectDto.IdDep,
                Name        = projectDto.Name,
                Description = projectDto.Description,
                StartDate   = projectDto.StartDate.Date,
                FinalDate   = projectDto.Finaldate.Date,
            };

            if (id != project.NProject)
            {
                return(BadRequest());
            }

            if (!ProjectsExists(id))
            {
                return(NotFound());
            }

            //Verifica se existe um departamento com o código passado.
            if (!_context.Departments.Any(e => e.IdDep == project.IdDep))
            {
                return(NotFound(new {
                    IdDep = project.IdDep,
                    title = "Not Found",
                    status = "404",
                    message = "department not found"
                }));
            }

            _context.Entry(project).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectsExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployees(decimal id, EmployeeDto employeeDto)
        {
            Employee employee = new Employee {
                IdEmployee = employeeDto.IdEmployee,
                Name       = employeeDto.Name,
                BirthDate  = employeeDto.BirthDate.Date,
                Salary     = employeeDto.Salary,
                Sex        = employeeDto.Sex
            };

            if (id != employee.IdEmployee)
            {
                return(BadRequest());
            }

            if (!EmployeesExists(id))
            {
                return(NotFound());
            }

            _context.Entry(employee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        public async Task <IActionResult> PutDepartments(decimal id, DepartmentDto departmentDto)
        {
            Department departments = new Department {
                IdDep       = departmentDto.IdDep,
                Name        = departmentDto.Name,
                Description = departmentDto.Description
            };

            if (id != departments.IdDep)
            {
                return(BadRequest());
            }

            if (!DepartmentsExists(id))
            {
                return(NotFound());
            }

            _context.Entry(departments).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }