示例#1
0
        public async Task <IActionResult> UpdateEmployee(int id, [FromBody] UpdateEmployeeDTO employeeDTO)
        {
            if (!ModelState.IsValid || id < 1)
            {
                _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateEmployee)}");
                return(BadRequest(ModelState));
            }

            try
            {
                var employee = await _unitOfWork.Employee.Get(q => q.Id == id);

                if (employee == null)
                {
                    _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateEmployee)}");
                    return(BadRequest("IData submitted is invalid"));
                }

                _mapper.Map(employeeDTO, employee);
                _unitOfWork.Employee.Update(employee);
                await _unitOfWork.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Something went wrong in the {nameof(UpdateEmployee)}");
                return(StatusCode(500, "Internal Server Error. Please try again later."));
            }
        }
示例#2
0
        /// <inheritdoc/>
        public EmployeeDTO Update(UpdateEmployeeDTO updateEmployeeDTO)
        {
            var employee = mapper.Map <Employee>(updateEmployeeDTO);
            var entity   = employeeManager.Update(employee);

            return(mapper.Map <EmployeeDTO>(entity));
        }
        public async Task <Employee> execute(Guid id, UpdateEmployeeDTO model)
        {
            var employee = await _repository.GetByID(id);

            if (employee == null)
            {
                throw new AppException(HttpStatusCode.NotFound, "Employee not found");
            }

            if (model.name != null)
            {
                employee.name = model.name;
            }

            if (model.lastName != null)
            {
                employee.lastName = model.lastName;
            }

            if (model.document != null)
            {
                employee.document = model.document;
            }

            if (model.grossWage.HasValue)
            {
                employee.grossWage = (decimal)model.grossWage;
            }

            if (model.admissionDate.HasValue)
            {
                employee.admissionDate = (DateTime)model.admissionDate;
            }

            if (model.hasHealthPlan.HasValue)
            {
                employee.hasHealthPlan = (bool)model.hasHealthPlan;
            }

            if (model.hasDentalPlan.HasValue)
            {
                employee.hasDentalPlan = (bool)model.hasDentalPlan;
            }

            if (model.hasTransportationVouchersDiscount.HasValue)
            {
                employee.hasTransportationVouchersDiscount = (bool)model.hasTransportationVouchersDiscount;
            }

            return(await _repository.Update(employee));
        }
示例#4
0
 public async Task <ActionResult <Employee> > Update(
     [FromServices] UpdateEmployeeService service,
     [FromBody] UpdateEmployeeDTO model,
     Guid id)
 {
     if (ModelState.IsValid)
     {
         return(await service.execute(id, model));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
示例#5
0
        /// <summary>
        /// Update an employee.
        /// </summary>
        /// <param name="id">ID of employee to search for.</param>
        /// <param name="model">Data to be updated.</param>
        /// <returns></returns>
        public EmployeeDTO Update(int id, UpdateEmployeeDTO model)
        {
            var employee = FindEmployee(id);

            employee.FirstName = model.FirstName ?? employee.FirstName;
            employee.LastName  = model.LastName ?? employee.LastName;
            employee.Email     = model.Email ?? employee.Email;
            if (model.AddressId != 0)
            {
                this.addressService.GetBaseForTest(model.AddressId);
                employee.AddressId  = model.AddressId;
                employee.ModifiedOn = DateTime.UtcNow;
            }
            this.dbContext.SaveChanges();
            return(new EmployeeDTO(employee));
        }
 public async Task <GetEmployeeDTO> Put([FromRoute] int id, [FromBody] UpdateEmployeeDTO value)
 {
     return(await _service.Update(id, value));
 }
 public IActionResult Update([FromHeader] string authorizationUsername, int id, [FromBody] UpdateEmployeeDTO model)
 {
     try
     {
         this.authHelper.TryGetEmployee(authorizationUsername);
         var employee = this.employeeService.Update(id, model);
         return(Ok(employee));
     }
     catch (Exception e)
     {
         return(NotFound(e.Message));
     }
 }