예제 #1
0
        public async Task UpdateProfile(ProfileDto dto)
        {
            try
            {
                using (DHContext db = new DHContext())
                {
                    var entity = await db.Profiles.Where(p => p.Id == dto.Id).FirstOrDefaultAsync();

                    entity.FirstName       = dto.FirstName;
                    entity.LastName        = dto.LastName;
                    entity.MiddleName      = dto.MiddleName;
                    entity.Gender          = dto.Gender;
                    db.Entry(entity).State = EntityState.Modified;
                    await db.SaveChangesAsync();
                }
            }
            catch (Exception exc)
            {
                _logger.Error($"Failed update profile {dto.Id} : {exc}");
                throw;
            }
        }
예제 #2
0
        public async Task <bool> Register(AccountRegisterDto dto)
        {
            try
            {
                Guid    Userid      = Guid.NewGuid();
                Guid    ProfileId   = Guid.NewGuid();
                RoleDto defaultRole = await GetRole("Default");

                using (DHContext db = new DHContext())
                {
                    Profile profile = new Profile
                    {
                        Id         = ProfileId,
                        FirstName  = string.Empty,
                        Gender     = string.Empty,
                        LastName   = string.Empty,
                        MiddleName = string.Empty,
                        UserId     = Userid
                    };
                    User user = new User
                    {
                        Login        = dto.Login,
                        Id           = Userid,
                        RoleId       = defaultRole.Id,
                        HashPassword = HashPassword(dto.Password),
                        ProfileId    = ProfileId
                    };
                    db.Users.Add(user);
                    db.Profiles.Add(profile);
                    await db.SaveChangesAsync();
                }
                return(true);
            }
            catch (Exception exc)
            {
                _logger.Error($"Failed register new user {dto.Login} : {exc}");
                return(false);
            }
        }