Exemplo n.º 1
0
        public async Task <IActionResult> UpdateDepartment([FromBody] UpdateCountryModel updateDepartmentModel)
        {
            UpdateDepartmentDto updateDepartmentDto = _mapper.Map <UpdateDepartmentDto>(updateDepartmentModel);
            await _departmentService.UpdateDepartmentAsync(updateDepartmentDto);

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateCountry([FromBody] UpdateCountryModel updateCountryModel)
        {
            UpdateCountryDto updateCountryDto = _mapper.Map <UpdateCountryDto>(updateCountryModel);
            await _countryService.UpdateCountryAsync(updateCountryDto);

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <TResponse <bool> > Update(int userId,
                                                     UpdateCountryModel request,
                                                     int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId,
                                                                    permissionId);

                if (checkValid.IsSuccess)
                {
                    var canUpdate = await CanUpdate(request);

                    if (canUpdate.IsSuccess)
                    {
                        var result = await WriteRepository.ExecuteAsync(SqlQuery.COUNTRY_UPDATE,
                                                                        new
                        {
                            request.Id,
                            request.Name,
                            UserUpdated = userId,
                            DateUpdated = DateTime.Now
                        });

                        if (result.IsSuccess)
                        {
                            if (result.Data > 0)
                            {
                                #region Update redis cache

                                await _countryCacheService.AddOrUpdate(new CountryCacheModel
                                {
                                    Id   = request.Id,
                                    Name = request.Name
                                });

                                #endregion

                                return(await Ok(true));
                            }

                            return(await Fail <bool>(ErrorEnum.BAD_REQUEST.GetStringValue()));
                        }

                        return(await Fail <bool>(result.Message));
                    }

                    return(await Fail <bool>(canUpdate.Message));
                }

                return(await Fail <bool>(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult <CountryModel> > Put(Guid id, [FromBody] UpdateCountryModel model)
        {
            try
            {
                if (id != model.Id)
                {
                    return(BadRequest());
                }

                return(Ok(await this.handler.UpdateAsync(model)));
            }
            catch (Exception)
            {
                // here we should capture the custom exception to return the correct response
                throw;
            }
        }
Exemplo n.º 5
0
        private async Task <TResponse <bool> > CanUpdate(UpdateCountryModel request)
        {
            try
            {
                var country = await _countryCacheService.GetByName(request.Name);

                if (country != null &&
                    country.Id != request.Id)
                {
                    return(await Fail <bool>(ErrorEnum.COUNTRY_HAS_EXIST.GetStringValue()));
                }

                return(await Ok(true));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
Exemplo n.º 6
0
 public async Task <ActionResult <bool> > Update(UpdateCountryModel request)
 {
     return(Ok(await _countryService.Update(await GetUserId(),
                                            request,
                                            GetPermissionId())));
 }