Exemple #1
0
        public async Task <int> AddItem(T item)
        {
            await _entities.AddAsync(item);

            await _context.SaveChangesAsync();

            return(item.ID);
        }
        public async Task <UserManagerResponse> UpdateUserInfoAsync(string userId, UserEditReadDto userEditDto)
        {
            var user = await _UserManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(new UserManagerResponse
                {
                    IsSuccessful = false,
                    Message = "user not found"
                });
            }

            if (!string.IsNullOrEmpty(userEditDto.FirstName))
            {
                user.FirstName = userEditDto.FirstName;
            }
            if (!string.IsNullOrEmpty(userEditDto.LastName))
            {
                user.LastName = userEditDto.LastName;
            }
            if (!string.IsNullOrEmpty(userEditDto.Address))
            {
                user.Address = userEditDto.Address;
            }
            if (!string.IsNullOrEmpty(userEditDto.City))
            {
                user.City = userEditDto.City;
            }
            if (!string.IsNullOrEmpty(userEditDto.AdditionalInfo))
            {
                user.AdditionalInfo = userEditDto.AdditionalInfo;
            }
            if (!string.IsNullOrEmpty(userEditDto.PhoneNumber))
            {
                user.PhoneNumber = userEditDto.PhoneNumber;
            }
            if (!string.IsNullOrEmpty(userEditDto.PhoneNumber))
            {
                user.Region = userEditDto.Region;
            }

            var result = await _UserManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                return(new UserManagerResponse
                {
                    IsSuccessful = false,
                    Message = "Process Failed",
                    Errors = result.Errors.Select(e => e.Description)
                });
            }
            await _DbContext.SaveChangesAsync();

            return(new UserManagerResponse
            {
                IsSuccessful = true,
                Message = "User info updated successfully"
            });
        }