public ActionResult Create(int templateId)
        {
            var user = Repository.OfType<User>().Queryable.Where(a => a.LoginId == CurrentUser.Identity.Name).Single();
            if (!_accessService.HasAccess(templateId, null, CurrentUser.Identity.Name))
            {
                Message = string.Format(StaticValues.Message_NoAccess, "that template");
                return this.RedirectToAction<HomeController>(a => a.Index());
            }
            var template = Repository.OfType<Template>().GetNullableById(templateId);

            var callforproposalToCreate = new CallForProposal(template, user);
            callforproposalToCreate.EndDate = DateTime.Now.AddMonths(1).Date;
            callforproposalToCreate.IsActive = false;

            callforproposalToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _callforproposalRepository.EnsurePersistent(callforproposalToCreate);

                Message = string.Format(StaticValues.Message_CreatedSuccessfully, "Call For Proposal");

                return this.RedirectToAction(a => a.Edit(callforproposalToCreate.Id));
            }
            else
            {
                Message = string.Format(StaticValues.Message_ProblemSelecting, "that template");
                var viewModel = CallForProposalCreateViewModel.Create(Repository, CurrentUser.Identity.Name);

                return View(viewModel);
            }
        }
示例#2
0
        public static AddEditorViewModel Create(IRepository repository, Template template, CallForProposal callForProposal)
        {
            Check.Require(repository != null, "Repository is required.");

            var viewModel = new AddEditorViewModel()
            {
                Template = template,
                CallForProposal = callForProposal,
                Users = repository.OfType<User>().Queryable.OrderBy(a => a.LastName).ToList()
            };
            if (template != null)
            {
                viewModel.IsTemplate = true;
                viewModel.TemplateId = template.Id;
            }
            else if (callForProposal != null)
            {
                viewModel.IsCallForProposal = true;
                viewModel.CallForProposalId = callForProposal.Id;
            }

            Check.Require(viewModel.IsTemplate || viewModel.IsCallForProposal, "Must have either a template or a call for proposal");

            return viewModel;
        }
示例#3
0
        public static EmailQueueViewModel Create(IRepository repository, CallForProposal callForProposal)
        {
            Check.Require(repository != null, "Repository must be supplied");

            var viewModel = new EmailQueueViewModel { EmailQueue = new EmailQueue(), CallForProposal = callForProposal};

            return viewModel;
        }
示例#4
0
        public static ReportLaunchViewModel Create(IRepository repository, CallForProposal callForProposal, Report report, bool forExport = false)
        {
            Check.Require(repository != null, "Repository must be supplied");
            var viewModel = new ReportLaunchViewModel { CallForProposal = callForProposal, Report = report, ForExport = forExport};
            viewModel.AvailableQuestions = callForProposal.Questions.Select(a => a.Name).ToList();

            return GenerateGeneric(viewModel, report, callForProposal);
        }
示例#5
0
        public static EmailsForCallSendViewModel Create(IRepository repository, CallForProposal callForProposal)
        {
            Check.Require(repository != null, "Repository must be supplied");
            var viewModel = new EmailsForCallSendViewModel {CallForProposal = callForProposal, Immediate = false};

            viewModel.EmailsForCallList = repository.OfType<EmailsForCall>().Queryable.Where(a => a.CallForProposal != null && a.CallForProposal == callForProposal);

            return viewModel;
        }
示例#6
0
        public static EmailQueueListViewModel Create(IRepository repository, CallForProposal callForProposal)
        {
            Check.Require(repository != null, "Repository must be supplied");

            var viewModel = new EmailQueueListViewModel{CallForProposal = callForProposal};
            viewModel.EmailQueues = repository.OfType<EmailQueue>().Queryable.Where(a => a.CallForProposal == callForProposal);

            return viewModel;
        }
示例#7
0
        public static EmailsForCallViewModel Create(IRepository repository, Template template, CallForProposal callForProposal)
        {
            Check.Require(repository != null, "Repository must be supplied");

            var viewModel = new EmailsForCallViewModel { EmailsForCall = new EmailsForCall() };
            if (template != null)
            {
                viewModel.IsTemplate = true;
                viewModel.TemplateId = template.Id;
            }
            else if (callForProposal != null)
            {
                viewModel.IsCallForProposal = true;
                viewModel.CallForProposalId = callForProposal.Id;
            }

            Check.Require(viewModel.IsTemplate || viewModel.IsCallForProposal, "Must have either a template or a call for proposal");
            return viewModel;
        }
 /// <summary>
 /// Transfer editable values from source to destination
 /// </summary>
 private static void TransferValues(CallForProposal source, CallForProposal destination)
 {
     destination.Name = source.Name;
     destination.EndDate = source.EndDate;
     destination.IsActive = source.IsActive;
     destination.ProposalMaximum = source.ProposalMaximum;
     destination.Description = source.Description;
     destination.HideInvestigators = source.HideInvestigators;
 }
        public ActionResult Edit(int id, CallForProposal callforproposal)
        {
            var callforproposalToEdit = _callforproposalRepository.GetNullableById(id);

            if (callforproposalToEdit == null)
            {
                return this.RedirectToAction(a => a.Index(null, null, null));
            }

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

            TransferValues(callforproposal, callforproposalToEdit);

            callforproposalToEdit.TransferValidationMessagesTo(ModelState);

            //if (callforproposalToEdit.ProposalMaximum < 0.01m)
            //{
            //    ModelState.AddModelError("CallForProposal.ProposalMaximum", "You need to specify a Proposal Maximum of at least a cent");
            //}

            if (callforproposalToEdit.IsActive && string.IsNullOrWhiteSpace(callforproposalToEdit.Description))
            {
                ModelState.AddModelError("CallForProposal.Description", "Please supply a description");
            }

            if (ModelState.IsValid)
            {
                _callforproposalRepository.EnsurePersistent(callforproposalToEdit);

                Message = string.Format(StaticValues.Message_EditedSuccessfully, "Call For Proposal");//"CallForProposal Edited Successfully";

                return this.RedirectToAction(a => a.Edit(callforproposalToEdit.Id));
            }
            else
            {
                var viewModel = CallForProposalViewModel.Create(Repository);
                viewModel.CallForProposal = callforproposalToEdit;
                viewModel.CallForProposalId = callforproposalToEdit.Id;
                viewModel.TemplateId = null;

                return View(viewModel);
            }
        }
示例#10
0
        private static ReportLaunchViewModel GenerateGeneric(ReportLaunchViewModel viewModel, Report report, CallForProposal callForProposal)
        {
            //deal with the column names
            foreach (var reportColumn in report.ReportColumns)
            {
                if (reportColumn.IsProperty || viewModel.AvailableQuestions.Contains(reportColumn.Name))
                {
                    viewModel.ColumnNames.Add(Inflector.Titleize(Inflector.Humanize(Inflector.Underscore(reportColumn.Name))));
                }
            }

            var proposals = callForProposal.Proposals.AsQueryable();
            if (!report.ShowUnsubmitted)
            {
                proposals = proposals.Where(a => a.IsSubmitted);
            }
            //foreach (var proposal in callForProposal.Proposals.Where(a => a.IsSubmitted))
            foreach (var proposal in proposals)
            {
                var row = new List<string>();

                foreach (var reportColumn in report.ReportColumns)
                {
                    if (reportColumn.IsProperty || viewModel.AvailableQuestions.Contains(reportColumn.Name))
                    {
                        row.Add(ExtractValue(reportColumn, proposal, viewModel.ForExport));
                    }
                }

                viewModel.RowValues.Add(row.ToArray());
            }

            return viewModel;
        }
示例#11
0
        public static ReviewersSendViewModel Create(IRepository repository, CallForProposal callForProposal)
        {
            Check.Require(repository != null, "Repository must be supplied");
            var viewModel = new ReviewersSendViewModel { CallForProposal = callForProposal, Immediate = false };

            viewModel.EditorsToNotify = repository.OfType<Editor>().Queryable.Where(a => a.CallForProposal != null && a.CallForProposal == callForProposal && a.User == null);

            return viewModel;
        }
示例#12
0
 public static CallNavigationViewModel Create(CallForProposal callForProposal)
 {
     return new CallNavigationViewModel{CallForProposal = callForProposal};
 }