Ejemplo n.º 1
0
        public virtual void BlockOrUnBlock(BlockMemberViewModel viewModel)
        {
            if (Request.IsAjaxRequest())
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        // Get a db user
                        var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id);

                        // Other member
                        var otherMember = MembershipService.GetUser(viewModel.MemberToBlockOrUnBlock);

                        var block = loggedOnUser.BlockedUsers.FirstOrDefault(x => x.Blocked.Id == otherMember.Id);
                        if (block != null)
                        {
                            var getBlock = _blockService.Get(block.Id);
                            _blockService.Delete(getBlock);
                        }
                        else
                        {
                            loggedOnUser.BlockedUsers.Add(new Block
                            {
                                Blocked = otherMember, Blocker = loggedOnUser, Date = DateTime.Now
                            });
                        }

                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex);
                        throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public virtual void BlockOrUnBlock(EntityIdViewModel viewModel)
        {
            if (Request.IsAjaxRequest())
            {
                try
                {
                    // Get a db user
                    var loggedOnUser = MembershipService.GetUser(User.Identity.Name, true);

                    // Other member
                    MembershipUser otherMember = MembershipService.GetUser(viewModel.Id);

                    var block = loggedOnUser.BlockedUsers.FirstOrDefault(x => x.Blocked.Id == otherMember.Id);
                    if (block != null)
                    {
                        var getBlock = _blockService.Get(block.Id);
                        _blockService.Delete(getBlock);
                    }
                    else
                    {
                        loggedOnUser.BlockedUsers.Add(new Block
                        {
                            Blocked = otherMember,
                            Blocker = loggedOnUser,
                            Date    = DateTime.Now
                        });
                    }

                    Context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Context.RollBack();
                    LoggingService.Error(ex);
                    throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }
            }
        }
Ejemplo n.º 3
0
 public async Task <IActionResult> GetBlock([FromQuery] string id, [FromQuery] string siteId)
 => OkOrBadRequest(await blockService.Get(id, siteId));