Esempio n. 1
0
        private ServiceFollowing MappingData(ServiceFollowingViewModel vm)
        {
            ServiceFollowing serviceFollowing = new ServiceFollowing();

            serviceFollowing.UserId    = Guid.Parse(vm.UserId);
            serviceFollowing.ServiceId = Guid.Parse(vm.ServiceId);
            return(serviceFollowing);
        }
        public async Task <CommandResult <ServiceFollowingViewModel> > ExecuteAsync(ServiceFollowingViewModel model)
        {
            var userId   = _httpContextAccessor.HttpContext.User.Identity.Name;
            var userName = await _userManager.FindByIdAsync(userId);

            try
            {
                var checkUserHasFollow = await _serviceFollowingRepository.FindByIdAsync(model.Id);

                if (checkUserHasFollow == null)
                {
                    await Logging <UnFollowPostServiceCommand> .
                    ErrorAsync(ActionCommand.COMMAND_ADD, userName.UserName, ErrorMessageConstant.ERROR_CANNOT_FIND_ID);

                    return(new CommandResult <ServiceFollowingViewModel>
                    {
                        isValid = false,
                        errorMessage = ErrorMessageConstant.ERROR_CANNOT_FIND_ID
                    });
                }
                _serviceFollowingRepository.Remove(checkUserHasFollow);
                await _serviceFollowingRepository.SaveAsync();

                await Logging <UnFollowPostServiceCommand>
                .InformationAsync(ActionCommand.COMMAND_ADD, userName.UserName, JsonConvert.SerializeObject(checkUserHasFollow));

                return(new CommandResult <ServiceFollowingViewModel>
                {
                    isValid = true,
                    myModel = model
                });
            }
            catch (Exception ex)
            {
                await Logging <UnFollowPostServiceCommand> .ErrorAsync(ex, ActionCommand.COMMAND_UPDATE, userName.UserName, "Has error");

                return(new CommandResult <ServiceFollowingViewModel>
                {
                    isValid = false,
                    errorMessage = ex.InnerException.Message.ToString()
                });
            }
        }
Esempio n. 3
0
        public async Task <CommandResult <ServiceFollowingViewModel> > ExecuteAsync(ServiceFollowingViewModel serviceFollowingViewModel)
        {
            var userId   = _httpContextAccessor.HttpContext.User.Identity.Name;
            var userName = await _userManager.FindByIdAsync(userId);

            try
            {
                var checkUserHasFollow = await _serviceFollowingRepository.FindSingleAsync(x =>
                                                                                           x.ServiceId == Guid.Parse(serviceFollowingViewModel.ServiceId) &&
                                                                                           x.UserId == Guid.Parse(serviceFollowingViewModel.UserId));

                var getOwnerService = await _getOwnServiceInformationQuery.ExecuteAsync(serviceFollowingViewModel.ServiceId);

                if (checkUserHasFollow != null)
                {
                    await Logging <FollowPostServiceCommand> .ErrorAsync(ActionCommand.COMMAND_ADD, userName.UserName, "You had follow this service");

                    return(new CommandResult <ServiceFollowingViewModel>
                    {
                        isValid = false,
                        errorMessage = "You had follow this service"
                    });
                }
                var postService = await _serviceRepository.FindByIdAsync(Guid.Parse(serviceFollowingViewModel.ServiceId));

                if (postService == null)
                {
                    await Logging <FollowPostServiceCommand> .ErrorAsync(ActionCommand.COMMAND_ADD, userName.UserName, ErrorMessageConstant.ERROR_CANNOT_FIND_ID);

                    return(new CommandResult <ServiceFollowingViewModel>
                    {
                        isValid = false,
                        errorMessage = ErrorMessageConstant.ERROR_CANNOT_FIND_ID
                    });
                }
                var data = MappingData(serviceFollowingViewModel);
                await _serviceFollowingRepository.Add(data);

                await _serviceFollowingRepository.SaveAsync();

                await LoggingUser <FollowPostServiceCommand> .
                InformationAsync(getOwnerService, userName.UserName, userName.UserName + " had follow" + postService.ServiceName);

                await Logging <FollowPostServiceCommand> .InformationAsync(ActionCommand.COMMAND_ADD, userName.UserName, JsonConvert.SerializeObject(serviceFollowingViewModel));

                return(new CommandResult <ServiceFollowingViewModel>
                {
                    isValid = true,
                    myModel = serviceFollowingViewModel
                });
            }
            catch (Exception ex)
            {
                await Logging <FollowPostServiceCommand> .ErrorAsync(ex, ActionCommand.COMMAND_ADD, userName.UserName, "Has error");

                return(new CommandResult <ServiceFollowingViewModel>
                {
                    isValid = false,
                    errorMessage = ex.InnerException.Message.ToString()
                });
            }
        }
        public async Task <IActionResult> UnFollowService(ServiceFollowingViewModel vm)
        {
            var model = await _unFollowPostServiceCommand.ExecuteAsync(vm);

            return(new OkObjectResult(model));
        }