public async Task <IActionResult> UpdateProfile(int profileId, [FromBody] UpdateUserProfileRequest request)
        {
            var updateUserProfileCommand = new UpdateUserProfileCommand(profileId, request);
            var result = await mediator.Send(updateUserProfileCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
Beispiel #2
0
 private UserProfile CreateUserProfile(UpdateUserProfileCommand command)
 {
     return(new UserProfile(command.Id, command.Created)
     {
         UserId = command.UserId,
         Description = command.Description,
         EyeColor = Enumeration.FromName <EyeColor>(command.EyeColor)
     });
 }
Beispiel #3
0
        public async Task <ActionResult <Result> > UpdateUserProfile([FromBody] UpdateUserProfileCommand command)
        {
            var response = await Mediator.Send(command);

            if (!response.Succeeded)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Beispiel #4
0
 public async Task<IActionResult> UpdateProfile([FromBody]UserProfile profile, Guid id)
 {
     var cmd = new UpdateUserProfileCommand { UserId = id, NewProfile = profile };
     var result = await _sagaBus.InvokeAsync<UpdateUserProfileCommand, MessageResult>(cmd);
     if (result.Succeed)
     {
         return Created(Url.Action(), null);
     }
     //if user doesn't exist.
     return BadRequest(result.Message);
 }
Beispiel #5
0
        public async Task <IActionResult> UpdateUserProfile([FromRoute] Guid userId, [FromBody] UpdateUserProfileCommand request)
        {
            request.UserId = userId;
            var cmdResult = await _mediator.Send(request);

            if (cmdResult is false)
            {
                return(BadRequest(new { message = "could not update" }));
            }

            return(Ok(new { message = "user profile updated" }));
        }
        public ActionResult EditProfile(EditProfileViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var result = false;

                var avatar = GetAvatar();

                if (avatar == null)
                {
                    var avatarNull = new UpdateUserProfileCommand
                    {
                        UserId      = User.Identity.GetUserId(),
                        FirstName   = viewModel.FirstName,
                        LastName    = viewModel.LastName,
                        EnglishName = viewModel.EnglishName,
                        Gender      = viewModel.Gender,
                        DOB         = viewModel.DOB,
                        IdNumber    = viewModel.IdNumber
                    };

                    result = mediator.Send(avatarNull);
                }

                else
                {
                    var image = new UpdateUserProfileCommand
                    {
                        UserId      = User.Identity.GetUserId(),
                        File        = avatar,
                        FirstName   = viewModel.FirstName,
                        LastName    = viewModel.LastName,
                        EnglishName = viewModel.EnglishName,
                        Gender      = viewModel.Gender,
                        DOB         = viewModel.DOB,
                        IdNumber    = viewModel.IdNumber
                    };

                    result = mediator.Send(image);
                }

                if (result == true)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                return(RedirectToAction("Index", new { message = ManageMessageId.Error }));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #7
0
        public async Task <IActionResult> UpdateProfile([FromBody] UserProfile profile, Guid id)
        {
            var cmd = new UpdateUserProfileCommand {
                UserId = id, NewProfile = profile
            };
            var result = await _sagaBus.InvokeAsync <UpdateUserProfileCommand, MessageResult>(cmd);

            if (result.Succeed)
            {
                return(Created(Url.Action(), null));
            }
            //if user doesn't exist.
            return(BadRequest(result.Message));
        }
Beispiel #8
0
        public async Task <IActionResult> UpdateUserProfile([FromBody] UpdateUserProfileCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //var f = Request.Form.Files;

            //if (f.Count > 0)
            //{
            //    command.AvatarImage = f[0];
            //}


            //if (command.AvatarImage == null || command.AvatarImage.Length == 0)
            //    return Content("file not selected");

            var result = await _mediator.Send(command);

            return(Ok(result));
        }
 public async Task <ActionResult> Put(UpdateUserProfileCommand command, CancellationToken cancellationToken) =>
 Result(await _mediator.Send(command, cancellationToken));
Beispiel #10
0
 public Task <Response <UserProfile> > UpdateUserProfile(UpdateUserProfileCommand command)
 {
     return(_context.UpdateUserProfile(command));
 }
 public async Task Post([FromBody] UpdateUserProfileCommand command)
 {
     await CommandPublisher.ExecuteAsync(command);
 }
Beispiel #12
0
        async Task <UpdateUserProfileCommandResult> IRequestHandler <UpdateUserProfileCommand, UpdateUserProfileCommandResult> .Handle(UpdateUserProfileCommand request, CancellationToken cancellationToken)
        {
            Log.Information("Updating user profile...", request);
            var result = await _store.UpdateItem(CreateUserProfile(request), cancellationToken);

            if (result.Result == ResultType.Notfound)
            {
                Log.Information($"Could not find user profile user with ID {request.UserId}.", result);
                return(new UpdateUserProfileCommandResult(request));
            }
            else
            {
                Log.Information("Succesfully updated user profile.", result);

                var commandResult = new UpdateUserProfileCommandResult(request, result);
                commandResult.AddDomainEvent(UserProfileUpdatedDomainEvent.Create(result.Resource, result.Etag));
                return(commandResult);
            }
        }