Esempio n. 1
0
        public async Task <bool> UpdateAsync(string id, [FromBody] UserDTO dto)
        {
            var entity = await _dbContext.Users.FirstOrDefaultAsync(x => x.Id == id);

            if (entity == null)
            {
                throw new ArgumentException("User not exists");
            }

            entity.SetModificationAudited(Session.UserId, Session.UserName);
            entity.Modify(dto.UserName, dto.Email, dto.PhoneNumber, dto.Source);

            _dbContext.Users.Update(entity);
            DateTime.TryParse(dto.Birthday, out var birthday);
            await _dbContext.AddOrUpdateUserClaimsAsync(id,
                                                        new Dictionary <string, string>
            {
                { "bio", dto.Bio },
                { "company", dto.Company },
                { "department", dto.Department },
                { "fax", dto.Fax },
                { "location", dto.Location },
                { "telephone", dto.Telephone },
                { "title", dto.Title },
                { "nickname", dto.NickName },
                {
                    JwtRegisteredClaimNames.Birthdate,
                    birthday == DateTime.MinValue ? "" : birthday.ToString("yyyy-MM-dd")
                },
                { JwtRegisteredClaimNames.Website, dto.Website },
                { JwtRegisteredClaimNames.FamilyName, dto.FamilyName },
                { JwtRegisteredClaimNames.GivenName, dto.GivenName },
                { JwtRegisteredClaimNames.Gender, dto.Sex }
            });

            return(true);
        }