Exemplo n.º 1
0
        public async Task <IHttpActionResult> Create([FromBody] CreatePersonnelDto personnel)
        {
            if (personnel == null)
            {
                return(BadRequest());
            }
            //custom validations
            var validator = new CreatePersonnelDtoValidator();
            var results   = validator.Validate(personnel);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage);
                }
            }
            if (!ModelState.IsValid)
            {
                string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
                return(BadRequest(errorMessage));
            }
            try
            {
                var result = await _personnelService.Create(personnel);

                if (!result.IsValid)
                {
                    return(BadRequest(result.Message));
                }
            }
            catch (LogicalException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
            }
            return(Ok());
        }
        public IHttpActionResult Update([FromBody] UpdateWorkingHourDto workingHour)
        {
            if (workingHour == null)
            {
                return(BadRequest());
            }
            //custom validations
            var validator = new UpdateWorkingHourDtoValidator();
            var results   = validator.Validate(workingHour);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage);
                }
            }
            if (!ModelState.IsValid)
            {
                string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
                return(BadRequest(errorMessage));
            }
            try
            {
                var result = _workingHourService.Update(workingHour);
                if (!result.IsValid)
                {
                    return(BadRequest(result.Message));
                }
                return(Ok());
            }
            catch (LogicalException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([FromBody] UserModel model)
        {
            try
            {
                if (model == null || !ModelState.IsValid)
                {
                    var errors = ModelStateError.GetErrors(ModelState);
                    return(StatusCode(StatusCodes.Status400BadRequest, errors));
                }

                var exist = await _userService.IsUserExistsAsync(model.Username, model.Email);

                if (exist)
                {
                    return(Ok(new Response
                    {
                        Data = null,
                        ErrorMessage = "Username or Email already exists",
                        Status = (int)ResponseStatus.UserNotExist
                    }));
                }

                var user = await _userService.CreateAsync(model);

                return(Ok(new Response
                {
                    Status = (int)ResponseStatus.Success,
                    Data = user.Id
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response
                {
                    ErrorMessage = "Something went wrong"
                }));
            }
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> Create([FromBody] CreatePersonnelShiftReplacementDto
                                                     personnelShiftReplacement)
        {
            if (personnelShiftReplacement == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
                return(BadRequest(errorMessage));
            }
            try
            {
                var result = await _personnelShiftReplacementService
                             .Create(personnelShiftReplacement, User.Identity.Name);

                if (result.ReturnId != null)
                {
                    await _notificationService.NotifyUpdates(result.ReturnId);
                }
                if (!result.IsValid)
                {
                    return(BadRequest(result.Message));
                }
            }
            catch (LogicalException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
            }
            return(Ok());
        }