예제 #1
0
        public IHttpActionResult Put(UserViewModel userViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var userDto = UserViewModelAdapter.BuildUserDto(userViewModel);

            _userManagementService.Edit(userDto, GetRequesterId());

            return(Ok());
        }
예제 #2
0
        public IHttpActionResult RegisterUser([FromBody] UserViewModel userViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = _userManagementService.IsUsernameAvailable(userViewModel.UserName);

            if (!user)
            {
                var response1 = Request.CreateResponse(HttpStatusCode.Forbidden, "Username not available");

                return(ResponseMessage(response1));
            }

            var userDto = UserViewModelAdapter.BuildUserDto(userViewModel);

            _userManagementService.Create(userViewModel.SubscriberEmail, userDto);

            var userSub = _userManagementService.GetUserByEmail(userViewModel.SubscriberEmail);

            var id = _signalRCache.GetConnectionId(userSub.Id);

            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            var notification = new NotificationDto()
            {
                Text   = $"User {userDto.UserName} requested access to your albums",
                UserId = userSub.Id
            };

            _notificationSerice.Save(notification);

            var ctx = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();

            ctx.Clients.Client(id).albumRequest(notification.Text);

            var response = Request.CreateResponse(HttpStatusCode.Created, userViewModel);

            return(ResponseMessage(response));
        }