/// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="parameter">
        /// User to delete
        /// </param>
        public override void Execute(object parameter)
        {
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, $"Exetute {nameof(DeleteFollowCommand)}");

            // gets user to delete
            D.User userToUnFollow = (D.User)parameter;
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, $"User nickname to unfollow {userToUnFollow.NickName}");

            // unfolow someone from you
            // or
            // unfollow oneself from somebody
            if (followViewModel.FollowMode == FollowMode.Followers)
            {
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Remove user from followers");
                followViewModel.DataStorage.ShownUser.Followers.Remove(userToUnFollow);
            }
            else if (followViewModel.FollowMode == FollowMode.Following)
            {
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Remove user from following");
                followViewModel.DataStorage.ShownUser.Following.Remove(userToUnFollow);
            }

            // update view
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update view");
            followViewModel.Users.Remove(userToUnFollow);

            // update DB
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Save changes to DataBase");
            followViewModel.UnitOfWork.UserRepository.Update(followViewModel.DataStorage.LoggedUser);
            followViewModel.UnitOfWork.UserRepository.Update(followViewModel.DataStorage.ShownUser);
            followViewModel.UnitOfWork.Save();
        }
Esempio n. 2
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 3
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new User { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        /// <summary>
        /// Executes command
        /// </summary>
        /// <param name="parameter">
        /// Current comment
        /// <para/>
        /// An array of values :
        /// <para/>
        /// 1 — bool value. True if like, false if dislike <para/>
        /// 2 — current comments wrapper
        /// </param>
        public override void Execute(object parameter)
        {
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, $"Execute {nameof(LikeCommentCommand)}");

            // gets value
            bool           isLike         = System.Convert.ToBoolean((parameter as System.Array).GetValue(0));
            CommentWrapper commentWrapper = (CommentWrapper)(parameter as System.Array).GetValue(1);

            DataAccess.Entities.User user = Services.DataStorage.Instance.LoggedUser;
            CommentLike commentLike       = photoInsideViewModel.UnitOfWork.CommentLikeRepository.TryGetUserLike(commentWrapper.Comment, user);

            // suitable for likes and dislikes
            // STEPS
            // 1. if like is new -> add it
            // 2. else if there is like or dislike
            //      2.1. if click on the same button type -> remove like
            //      2.2  else if click on the opposite button type -> toggle like

            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, isLike ? "Liking" : "Disliking");

            if (commentLike == null)// 1. add like
            {
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Add like");
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Add to data base");

                // update data base
                DataAccess.Context.UnitOfWork.Instance.CommentLikeRepository.Insert(new CommentLike
                {
                    IsLiked = isLike,
                    Comment = commentWrapper.Comment,
                    User    = user
                });

                // update view
                Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update View");
                if (isLike)
                {
                    ++commentWrapper.LikesAmount;
                }
                else
                {
                    ++commentWrapper.DisLikesAmount;
                }
            }
            else// 2. there is a like
            {
                if (commentLike.IsLiked == isLike)// 2.1 remove like
                {
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Remove like");
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update valuse in data base");

                    // updata data base
                    DataAccess.Context.UnitOfWork.Instance.CommentLikeRepository.Delete(commentLike);
                    DataAccess.Context.UnitOfWork.Instance.CommentRepository.Update(commentWrapper.Comment);

                    // update view
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update View");
                    if (isLike)
                    {
                        --commentWrapper.LikesAmount;
                    }
                    else
                    {
                        --commentWrapper.DisLikesAmount;
                    }
                }
                else// 2.2 toggle dislike to like
                {
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Toggle like");
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update valuse in data base");

                    // updata database
                    commentLike.IsLiked = isLike; // toggle
                    DataAccess.Context.UnitOfWork.Instance.CommentLikeRepository.Update(commentLike);


                    // update view, toggle value
                    Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Update View");
                    if (isLike)
                    {
                        ++commentWrapper.LikesAmount;
                        --commentWrapper.DisLikesAmount;
                    }
                    else
                    {
                        --commentWrapper.LikesAmount;
                        ++commentWrapper.DisLikesAmount;
                    }
                }
            }

            // save changes to database
            Core.Logger.GetLogger.LogAsync(Core.LogMode.Debug, "Save changes to data base");
            DataAccess.Context.UnitOfWork.Instance.Save();
        }