예제 #1
0
        public CommonResult DeleteGroup(DeleteGroupRequest request)
        {
            var groupResult = _groupsRepository.Get(request.GroupId, withOwner: true);

            if (groupResult.IsSuccess)
            {
                var group = groupResult.Item;

                if (group.Owner.UserName == request.UserName)
                {
                    return _groupsRepository.Delete(request.GroupId);
                }
                else
                {
                    return CommonResult.Failure("Tylko założyciel grupy może ją usunąć.");
                }
            }
            else
            {
                return CommonResult.Failure(groupResult.ErrorMessage);
            }
        }
예제 #2
0
        public IActionResult DeleteGroup(int groupId)
        {
            if (!CheckIfOwner(groupId, User.Identity.Name))
            {
                return RedirectToAction("Index");
            }

            var request = new DeleteGroupRequest
            {
                GroupId = groupId,
                UserName = User.Identity.Name
            };

            var deleteGroupResult = _groupsService.DeleteGroup(request);

            if (deleteGroupResult.IsSuccess)
            {
                return RedirectToAction("Index");
            }
            else
            {
                return RedirectToAction("Single", new { groupId = groupId });
            }
        }