Ejemplo n.º 1
0
        public async Task <IActionResult> AddUserSettings([FromBody] ModifiUserSettingsDTO userSettings)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(Resources.InValidData));
            }

            try
            {
                Log.Information($"Attempt modificate the user settings");
                var userId = 2; // modifeir id
                return(this.Ok(await this.userService.AddUserSettings(userSettings, userId)));
            }
            catch (Exception e)
            {
                return(this.BadRequest(e.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <ModifiUserSettingsDTO> AddUserSettings(ModifiUserSettingsDTO userSettings, int userId)
        {
            if (userSettings == null)
            {
                Log.Error(LogResources.EmptyArgument, nameof(userSettings));
                throw new ArgumentNullException();
            }

            if (userId <= 0)
            {
                throw new ArgumentException();
            }

            var user = await this.userSettingsRepository.GetAsync(userSettings.Id);

            if (user == null)
            {
                Log.Error(LogResources.IncorectArgument, nameof(userId));
                throw new ArgumentException();
            }

            user.FirstName    = userSettings.FirstName;
            user.LastName     = userSettings.LastName;
            user.Patronymic   = userSettings.Patronymic;
            user.DateOfBirth  = userSettings.DateOfBirth;
            user.ModifierDate = DateTime.Now;
            user.ModifierId   = userId;

            var result = await this.userSettingsRepository.UpdateAsync(user);

            if (result == null)
            {
                Log.Error("User settings not create");
                throw new InvalidOperationException("User setting not create");
            }

            Log.Debug("User settings is created");
            return(this.mapper.Map <ModifiUserSettingsDTO>(result));
        }