/// <summary> /// Executes command /// </summary> /// <param name="parameter"> /// Command parameters /// </param> public override void Execute(object parameter) { Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, $"Execute {nameof(WriteCommentCommand)}"); // gets comment text string commentText = photoInsideViewModel.CommentText; Core.Logger.GetLogger.LogAsync(Core.LogMode.Info, $"Get {nameof(commentText)} with value = {commentText}. Length = {commentText.Length}"); // create comment DataAccess.Entities.Comment comment = new DataAccess.Entities.Comment { Text = commentText, User = Services.DataStorage.Instance.LoggedUser, Photo = photoInsideViewModel.Photo }; Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Create comment"); // update view photoInsideViewModel.Comments.Add(new DataAccess.Wrappers.CommentWrapper(comment)); Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update view"); // update database photoInsideViewModel.UnitOfWork.CommentRepository.Insert(comment); photoInsideViewModel.UnitOfWork.Save(); Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update data base"); // clear current comment text Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Clear comment"); photoInsideViewModel.CommentText = string.Empty; }
// CONSTRUCTORS /// <summary> /// Initializes a new instance of <see cref="SingleViewModel"/> /// </summary> /// <param name="comment"> /// An instance of <see cref="DataAccess.Entities.Comment"/> /// </param> /// <param name="isEditingEnabled"> /// Determines if page is only for reading or not /// </param> /// <exception cref="System.ArgumentNullException"> /// Throws when <paramref name="comment"/> is null /// </exception> public SingleViewModel(DataAccess.Entities.Comment comment, bool isEditingEnabled) : base(shownEntity: comment, isWritingEnabled: isEditingEnabled) { ILookup <bool, string> groupedByLike = comment.Likes.ToLookup(c => c.IsLiked, u => u.User.NickName); this.likedUserNickname = groupedByLike[true].ToArray(); this.disLikedUserNickname = groupedByLike[false].ToArray(); // commands deleteOrUpdateCommand = isEditingEnabled ? (ICommand) new Commands.MultipleCommand(new CommandBase[] { new Commands.Admin.Comment.Single.ValidateCommand(this), new Commands.Admin.UpdateCommand() }) : (ICommand) new Commands.Admin.DeleteCommand(); }
// FILTERING METHOD /// <summary> /// Sets filter predicate /// </summary> /// <param name="entity"> /// The entities for which predicate is applied /// </param> /// <returns> /// Boolean values which determines if entity is allowed by predicate or not /// </returns> protected override bool FilterPredicate(object entity) { DataAccess.Entities.Comment commentToFilter = (DataAccess.Entities.Comment)entity; bool isShown = true; // checks text if (text != null) { isShown &= Has(comment: commentToFilter, textSubstring: text); } // checks date isShown &= Where(commentToFilter, from, to); // checks user nickname if (userNickname != null) { isShown &= Where(commentToFilter, userNickname); } return(isShown); }