Esempio n. 1
0
        public async Task <UULResponse> UpdateUsertAsync(UserWebInfoDTO dto)
        {
            UULResponse result;

            try {
                var data          = JsonConvert.SerializeObject(dto);
                var stringContent = new StringContent(data, UnicodeEncoding.UTF8, "application/json");
                using var httpResponse = await _httpClient.PostAsync("/api/webusers/update", stringContent);

                httpResponse.EnsureSuccessStatusCode();

                var jsonString = await httpResponse.Content.ReadAsStringAsync();

                var output = JsonConvert.DeserializeObject <UserWebInfoDTO>(jsonString);

                result = new UULResponse()
                {
                    Success = true, Data = output, Message = ""
                };
            } catch (Exception e) {
                result = new UULResponse()
                {
                    Success = false, Data = null, Message = e.Message
                };
            }
            return(result);
        }
Esempio n. 2
0
        public async Task <ActionResult <ICollection <UserWebInfoDTO> > > UpdateUser(UserWebInfoDTO userWebInfoDTO)
        {
            var userInfo = SecHelper.GetUserInfo(HttpContext.User.Claims);

            try {
                var user = await _context.Users.Where(u => u.Login.Equals(userInfo.Login) && u.ApartmentCode.Equals(userInfo.ApartmentCode)).SingleOrDefaultAsync();

                if (!SecHelper.IsAdmin(user))   // TODO move to claims
                {
                    throw new Exception("Not admin");
                }
                var userToUpdate = await _context.Users.FindAsync(userWebInfoDTO.ID);

                if (userToUpdate == null)
                {
                    return(new NotFoundResult());
                }
                userToUpdate.IsActivated = userWebInfoDTO.IsActivated; // currently only this
                _context.Users.Update(userToUpdate);
                await _context.SaveChangesAsync();

                return(new OkObjectResult(userWebInfoDTO));
            } catch {
                return(new ForbidResult());
            }
        }