public async Task <CommandResult <CommentViewModel> > ExecuteAsync(CommentViewModel commentserviceVm) { var userId = _httpContextAccessor.HttpContext.User.Identity.Name; var userName = await _userManager.FindByIdAsync(userId); try { var CommentUpdate = await _commentRepository.FindByIdAsync(commentserviceVm.Id); if (CommentUpdate != null) { CommentUpdate.ContentOfRating = commentserviceVm.ContentOfRating; CommentUpdate.UserId = Guid.Parse(commentserviceVm.UserId); CommentUpdate.ServiceId = Guid.Parse(commentserviceVm.ServiceId); var getUserService = await _getOwnServiceInformationQuery.ExecuteAsync(CommentUpdate.ServiceId.ToString()); _commentRepository.Update(CommentUpdate); await _commentRepository.SaveAsync(); await LoggingUser <UpdateCommentServiceAsyncCommand> .InformationAsync(getUserService, userName.UserName, CommentUpdate.ContentOfRating); await Logging <UpdateCommentServiceAsyncCommand> .InformationAsync(ActionCommand.COMMAND_UPDATE, userName.UserName, userName.UserName + " updated " + CommentUpdate.ContentOfRating); return(new CommandResult <CommentViewModel> { isValid = true, myModel = new CommentViewModel { Id = CommentUpdate.Id, UserId = CommentUpdate.UserId.ToString(), ServiceId = CommentUpdate.ServiceId.ToString(), ContentOfRating = CommentUpdate.ContentOfRating } }); } else { await Logging <UpdateCommentServiceAsyncCommand> .ErrorAsync(ActionCommand.COMMAND_UPDATE, userName.UserName, ErrorMessageConstant.ERROR_CANNOT_FIND_ID); return(new CommandResult <CommentViewModel> { isValid = false, errorMessage = ErrorMessageConstant.ERROR_CANNOT_FIND_ID }); } } catch (System.Exception ex) { await Logging <UpdateCommentServiceAsyncCommand> .ErrorAsync(ex, ActionCommand.COMMAND_UPDATE, userName.UserName, "Has error"); return(new CommandResult <CommentViewModel> { isValid = false, errorMessage = ex.InnerException.ToString() }); } }
public async Task <CommandResult <CommentViewModel> > ExecuteAsync(int id) { var userId = _httpContextAccessor.HttpContext.User.Identity.Name; var userName = await _userManager.FindByIdAsync(userId); try { var commentDel = await _commentRepository.FindByIdAsync(id); if (commentDel != null) { var getUserService = await _getOwnServiceInformationQuery.ExecuteAsync(commentDel.ServiceId.ToString()); _commentRepository.Remove(commentDel); await _commentRepository.SaveAsync(); await LoggingUser <DeleteCommentServiceAsyncCommand> .InformationAsync(getUserService, userName.UserName, commentDel.ContentOfRating); await Logging <DeleteCommentServiceAsyncCommand> .InformationAsync(ActionCommand.COMMAND_DELETE, userName.UserName, userName.UserName + " deleted " + commentDel.ContentOfRating); return(new CommandResult <CommentViewModel> { isValid = true, myModel = new CommentViewModel { Id = commentDel.Id, } }); } else { await Logging <DeleteCommentServiceAsyncCommand> .ErrorAsync(ActionCommand.COMMAND_DELETE, userName.UserName, ErrorMessageConstant.ERROR_CANNOT_FIND_ID); return(new CommandResult <CommentViewModel> { isValid = false, errorMessage = ErrorMessageConstant.ERROR_CANNOT_FIND_ID }); } } catch (System.Exception ex) { await Logging <DeleteCommentServiceAsyncCommand> .ErrorAsync(ex, ActionCommand.COMMAND_DELETE, userName.UserName, "Has error"); return(new CommandResult <CommentViewModel> { isValid = true, errorMessage = ex.InnerException.ToString() }); } }
public async Task <CommandResult <CommentViewModel> > ExecuteAsync(CommentViewModel addComment) { var userId = _httpContextAccessor.HttpContext.User.Identity.Name; var userName = await _userManager.FindByIdAsync(userId); try { var comment = new ServiceComment { ContentOfRating = addComment.ContentOfRating, UserId = Guid.Parse(addComment.UserId), ServiceId = Guid.Parse(addComment.ServiceId), ParentId = addComment.ParentId }; await _commentRepository.Add(comment); await _commentRepository.SaveAsync(); var getOwnerService = await _getOwnServiceInformationQuery.ExecuteAsync(addComment.ServiceId); await LoggingUser <AddCommentServiceAsyncCommand> . InformationAsync(getOwnerService, userName.UserName, addComment.ContentOfRating); await Logging <AddCommentServiceAsyncCommand> .InformationAsync(ActionCommand.COMMAND_ADD, userName.UserName, JsonConvert.SerializeObject(addComment)); return(new CommandResult <CommentViewModel> { isValid = true, myModel = new CommentViewModel { ContentOfRating = comment.ContentOfRating, Id = comment.Id, ParentId = comment.ParentId, ServiceId = comment.ServiceId.ToString(), UserId = comment.UserId.ToString() } }); } catch (Exception ex) { await Logging <AddCommentServiceAsyncCommand> .ErrorAsync(ex, ActionCommand.COMMAND_ADD, userName.UserName, "Has error"); return(new CommandResult <CommentViewModel> { isValid = false, errorMessage = ex.InnerException.Message.ToString() }); } }
public async Task <CommandResult <PostServiceViewModel> > ExecuteAsync(string idService, string reason) { var userId = _httpContextAccessor.HttpContext.User.Identity.Name; var userName = _userRepository.FindByIdAsync(userId).Result.UserName; try { //Check permission approve if (await _getPermissionActionQuery.ExecuteAsync(userId, ConstantFunctions.SERVICE, ActionSetting.CanUpdate) || await _checkUserIsAdminQuery.ExecuteAsync(userId)) { //Check have current post var getCurrentPost = await _postServiceRepository.FindByIdAsync(Guid.Parse(idService)); if (getCurrentPost != null) { var getUserId = await _getOwnServiceInformationQuery.ExecuteAsync(idService); getCurrentPost.Status = Status.Active; _postServiceRepository.Update(getCurrentPost); await _postServiceRepository.SaveAsync(); var findEmailUser = await GetEmailUserAsync(getCurrentPost); if (findEmailUser != ErrorMessageConstant.ERROR_CANNOT_FIND_ID) { //Set content for email //Get all email var getAllEmail = await _getAllEmailServiceQuery.ExecuteAsync(); var getFirstEmail = getAllEmail.Where(x => x.Name == EmailName.Reject_Service).FirstOrDefault(); getFirstEmail.Message = getFirstEmail.Message. Replace(EmailKey.ServiceNameKey, getCurrentPost.ServiceName) .Replace(EmailKey.UserNameKey, findEmailUser) .Replace(EmailKey.ReasonKey, reason); ContentEmail(_configEmail.Value.SendGridKey, getFirstEmail.Subject, getFirstEmail.Message, findEmailUser).Wait(); } else { await Logging <RejectPostServiceCommand> . WarningAsync(ActionCommand.COMMAND_APPROVE, userName, "Cannot find email"); return(new CommandResult <PostServiceViewModel> { isValid = false, errorMessage = "Cannot find email user" }); } //Write Log await Logging <RejectPostServiceCommand> . InformationAsync(ActionCommand.COMMAND_APPROVE, userName, getCurrentPost.ServiceName + "has been rejected"); await LoggingUser <RejectPostServiceCommand> . InformationAsync(getUserId, userName, userName + "Dịch vụ " + getCurrentPost.ServiceName + "đã bị từ chối. Check mail để xác nhận"); return(new CommandResult <PostServiceViewModel> { isValid = true, }); } //Write log await Logging <RejectPostServiceCommand> . WarningAsync(ActionCommand.COMMAND_APPROVE, userName, ErrorMessageConstant.ERROR_CANNOT_FIND_ID); return(new CommandResult <PostServiceViewModel> { isValid = false, errorMessage = ErrorMessageConstant.ERROR_CANNOT_FIND_ID }); } else { await Logging <RejectPostServiceCommand> . WarningAsync(ActionCommand.COMMAND_APPROVE, userName, ErrorMessageConstant.ERROR_UPDATE_PERMISSION); return(new CommandResult <PostServiceViewModel> { isValid = false, errorMessage = ErrorMessageConstant.ERROR_UPDATE_PERMISSION }); } } catch (System.Exception ex) { await Logging <RejectPostServiceCommand> . ErrorAsync(ex, ActionCommand.COMMAND_APPROVE, userName, "Has error"); return(new CommandResult <PostServiceViewModel> { isValid = false, errorMessage = ex.InnerException.ToString() }); } }
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 <CommandResult <ServiceRatingViewModel> > ExecuteAsync(ServiceRatingViewModel serviceRatingViewModel) { var getUserId = _httpContextAccessor.HttpContext.User.Identity.Name; var userName = _userManager.FindByIdAsync(getUserId).Result.UserName; try { //Check provider has available var getService = await _serviceRepository.FindByIdAsync(Guid.Parse(serviceRatingViewModel.ServiceId)); if (getService == null) { await Logging <AddUpdateRatingServiceCommand> .WarningAsync(ActionCommand.COMMAND_ADD, userName, ErrorMessageConstant.ERROR_CANNOT_FIND_ID); return(new CommandResult <ServiceRatingViewModel> { isValid = false, errorMessage = ErrorMessageConstant.ERROR_CANNOT_FIND_ID }); } var getServiceRating = await _serviceRatingRepository.FindSingleAsync(x => x.ServiceId == Guid.Parse(serviceRatingViewModel.ServiceId) && x.UserId == Guid.Parse(serviceRatingViewModel.UserId)); if (getServiceRating != null) { var getUserService = _getOwnServiceInformationQuery.ExecuteAsync(serviceRatingViewModel.ServiceId); getServiceRating.NumberOfRating = serviceRatingViewModel.NumberOfRating; getServiceRating.DateModified = DateTime.Now; _serviceRatingRepository.Update(getServiceRating); await _serviceRatingRepository.SaveAsync(); await LoggingUser <AddUpdateRatingServiceCommand> . InformationAsync(getUserId, userName, userName + "rated" + getService.ServiceName + " with" + getServiceRating.NumberOfRating); await Logging <AddUpdateRatingServiceCommand> .InformationAsync(ActionCommand.COMMAND_ADD, userName, JsonConvert.SerializeObject(serviceRatingViewModel)); return(new CommandResult <ServiceRatingViewModel> { isValid = true, myModel = serviceRatingViewModel }); } var query = new ServiceRating { NumberOfRating = serviceRatingViewModel.NumberOfRating, DateCreated = DateTime.Now, ServiceId = Guid.Parse(serviceRatingViewModel.ServiceId), UserId = Guid.Parse(getUserId) }; await _serviceRatingRepository.Add(query); await _serviceRatingRepository.SaveAsync(); await LoggingUser <AddUpdateRatingServiceCommand> . InformationAsync(getUserId, userName, userName + "rated" + getService.ServiceName + " with" + query.NumberOfRating); await Logging <AddUpdateRatingServiceCommand> .InformationAsync(ActionCommand.COMMAND_ADD, userName, JsonConvert.SerializeObject(serviceRatingViewModel)); return(new CommandResult <ServiceRatingViewModel> { isValid = true, myModel = serviceRatingViewModel }); } catch (Exception ex) { await Logging <AddUpdateRatingServiceCommand> . ErrorAsync(ex, ActionCommand.COMMAND_ADD, userName, "Has Error"); return(new CommandResult <ServiceRatingViewModel> { isValid = false, errorMessage = ex.InnerException.Message.ToString() }); } }