Esempio n. 1
0
        public ActionResult AddEditor(int? templateId, int? callForProposalId, int userId)
        {
            Template template = null;
            CallForProposal callforProposal = null;

            if (!_accessService.HasAccess(templateId, callForProposalId, CurrentUser.Identity.Name))
            {
                Message = string.Format(StaticValues.Message_NoAccess, "that");
                return this.RedirectToAction<HomeController>(a => a.Index());
            }

            if (templateId.HasValue && templateId != 0)
            {
                template = Repository.OfType<Template>().GetNullableById(templateId.Value);
            }
            else if (callForProposalId.HasValue && callForProposalId != 0)
            {
                callforProposal = Repository.OfType<CallForProposal>().GetNullableById(callForProposalId.Value);
            }

            var user = Repository.OfType<User>().GetNullableById(userId);
            if (user == null)
            {
                ModelState.AddModelError("User", "User not found");
                Message = "User not found";
            }

            var editor = new Editor(user, false);
            editor.CallForProposal = callforProposal;
            editor.Template = template;

            editor.TransferValidationMessagesTo(ModelState);

            if (editor.Template != null && _editorRepository.Queryable.Where(a => a.User != null && a.User == editor.User && a.Template != null && a.Template == template).Any())
            {
                ModelState.AddModelError("User", "User already exists");
                Message = "User already exists";
            }

            if (editor.CallForProposal != null && _editorRepository.Queryable.Where(a => a.User != null && a.User == editor.User && a.CallForProposal !=null && a.CallForProposal == callforProposal).Any())
            {
                ModelState.AddModelError("User", "User already exists");
                Message = "User already exists";
            }
            if (ModelState.IsValid)
            {
                Repository.OfType<Editor>().EnsurePersistent(editor);
                Message = "Editor Added";
            }
            else
            {
                Message = string.Format(string.Format("{0} {{0}}", string.Format(StaticValues.Message_UnableToAdd, "editor")), Message);
            }

            return this.RedirectToAction(a => a.Index(templateId, callForProposalId));
        }
Esempio n. 2
0
        public ActionResult CreateReviewer(int? templateId, int? callForProposalId, Editor editor)
        {
            Template template = null;
            CallForProposal callforProposal = null;

            if (!_accessService.HasAccess(templateId, callForProposalId, CurrentUser.Identity.Name))
            {
                Message = string.Format(StaticValues.Message_NoAccess, "that");
                return this.RedirectToAction<HomeController>(a => a.Index());
            }

            if (templateId.HasValue && templateId != 0)
            {
                template = Repository.OfType<Template>().GetNullableById(templateId.Value);
            }
            else if (callForProposalId.HasValue && callForProposalId !=0)
            {
                callforProposal = Repository.OfType<CallForProposal>().GetNullableById(callForProposalId.Value);
            }

            var editorToCreate = new Editor(editor.ReviewerEmail);

            TransferValues(editor, editorToCreate);
            editorToCreate.Template = template;
            editorToCreate.CallForProposal = callforProposal;

            editorToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _editorRepository.EnsurePersistent(editorToCreate);

                Message = string.Format(StaticValues.Message_CreatedSuccessfully, "Reviewer"); // "Reviewer Created Successfully";

                return this.RedirectToAction(a => a.Index(templateId, callForProposalId));
            }
            else
            {

                var viewModel = EditorViewModel.Create(Repository, template, callforProposal);
                viewModel.Editor = editorToCreate;

                return View(viewModel);
            }
        }