Esempio n. 1
0
        public async Task <bool> UpdateUser(AdditionShortRegisterInDto model)
        {
            var _      = model as AdditionShortRegisterInDto;
            var result = await _baseLogic.Of <Data.Context.User>().Base()
                         .AsNoTracking()
                         .FirstOrDefaultAsync(x => x.Login == _.Login);

            var role = await _baseLogic.Of <Role>().Base().FirstOrDefaultAsync(a => a.Value == model.RoleId);

            if (result != default)
            {
                result.LastName     = _.LastName;
                result.FirstName    = _.FirstName;
                result.MiddleName   = _.MiddleName;
                result.ContractorId = _.ContractorId;
                result.Email        = _.Email;
                //result.UserRoles.FirstOrDefault().RoleId = role.Id;
                await _baseLogic.Of <Data.Context.User>().Update(result);

                var userRole = await _baseLogic.Of <Data.Context.UserRole>().Base()
                               .FirstOrDefaultAsync(a => a.UserId == result.Id);

                userRole.RoleId = role.Id;
                await _baseLogic.Of <Data.Context.UserRole>().Update(userRole);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateUser([FromBody] AdditionShortRegisterInDto model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var _ = await _logic.UpdateUser(model);

                return(Ok(_));
            }
            catch (Exception e)
            {
                return(ExceptionResult(e));
            }
        }