コード例 #1
0
ファイル: SubsController.cs プロジェクト: skimur/skimur
        public ActionResult Edit(string subName, CreateEditSubModel model)
        {
            if (string.IsNullOrEmpty(subName))
                return Redirect(Url.Subs());

            model.IsEditing = true;
            model.Name = subName;

            var sub = _subDao.GetSubByName(subName);

            if (sub == null)
                return Redirect(Url.Subs(subName));

            if (!_permissionDao.CanUserManageSubConfig(_userContext.CurrentUser, sub.Id))
                throw new UnauthorizedException();

            var response = _commandBus.Send<EditSub, EditSubResponse>(new EditSub
            {
                EditedByUserId = _userContext.CurrentUser.Id,
                Name = subName,
                Description = model.Description,
                SidebarText = model.SidebarText,
                SubmissionText = model.SubmissionText,
                Type = model.SubType,
                IsDefault = model.IsDefault,
                Nsfw = model.Nsfw,
                InAll = model.InAll
            });

            if (!string.IsNullOrEmpty(response.Error))
            {
                ModelState.AddModelError(string.Empty, response.Error);
                return View(model);
            }

            // todo: success message

            return View(model);
        }
コード例 #2
0
ファイル: SubsController.cs プロジェクト: skimur/skimur
        public ActionResult Create()
        {
            var model = new CreateEditSubModel();

            // admins can create default subs!
            // not null means editable.
            if (_userContext.CurrentUser.IsAdmin)
                model.IsDefault = false;

            model.InAll = true;

            return View(model);
        }
コード例 #3
0
ファイル: SubsController.cs プロジェクト: skimur/skimur
        public ActionResult Create(CreateEditSubModel model)
        {
            var response = _commandBus.Send<CreateSub, CreateSubResponse>(new CreateSub
            {
                CreatedByUserId = _userContext.CurrentUser.Id,
                Name = model.Name,
                Description = model.Description,
                SidebarText = model.SidebarText,
                SubmissionText = model.SubmissionText,
                Type = model.SubType,
                IsDefault = model.IsDefault,
                InAll = model.InAll,
                Nsfw = model.Nsfw
            });

            if (!string.IsNullOrEmpty(response.Error))
            {
                ModelState.AddModelError(string.Empty, response.Error);
                return View(model);
            }

            AddSuccessMessage("You sub has been succesfully created.");

            return Redirect(Url.Sub(response.SubName));
        }