Exemplo n.º 1
0
        public async Task <IActionResult> EditConsultant(int id, ConsultForAddDto consultForAddDto)
        {
            //Validate
            var consultant = await _context.Consults.FirstOrDefaultAsync(x => x.Id == id);

            if (id != consultant.Id)
            {
                return(BadRequest());
            }
            if (consultant == null)
            {
                return(NotFound());
            }

            consultant.Name                       = consultForAddDto.Name;
            consultant.EmploymentDate             = consultForAddDto.EmploymentDate;
            consultant.InvoiceHoursWorkedThisYear = consultForAddDto.InvoiceHoursWorkedThisYear;

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddConsultant(ConsultForAddDto consultForAddDto)
        {
            //Validate

            consultForAddDto.Name = consultForAddDto.Name.ToLower();
            var consultToCreate = new Consult {
                Name = consultForAddDto.Name, EmploymentDate = consultForAddDto.EmploymentDate, InvoiceHoursWorkedThisYear = consultForAddDto.InvoiceHoursWorkedThisYear
            };

            _context.Consults.Add(consultToCreate);
            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }