Esempio n. 1
0
        public ActionResult Create(MailingList mailinglist, int?seminarId)
        {
            // make sure it's not a system mailing list
            if (_systemLists.Contains(mailinglist.Name))
            {
                ModelState.AddModelError("Name", "The name is the same as a system defined mailing list.");
            }

            // make sure one doesn't already exist
            if (mailinglist.Seminar.MailingLists.Any(a => a.Name == mailinglist.Name))
            {
                ModelState.AddModelError("Name", string.Format("A mailing list with the same name already exists for the {0} seminar.", mailinglist.Seminar.Year));
            }

            if (ModelState.IsValid)
            {
                _mailinglistRepository.EnsurePersistent(mailinglist);

                Message = "MailingList Created Successfully";

                //return RedirectToAction("Index");
                return(this.RedirectToAction(a => a.Index(seminarId)));
            }

            var viewModel = MailingListViewModel.Create(RepositoryFactory, Site, mailinglist, seminarId);

            viewModel.MailingList = mailinglist;

            return(View(viewModel));
        }
Esempio n. 2
0
        public ActionResult Edit(int id, MailingList mailinglist)
        {
            var existingMailingList = _mailinglistRepository.GetNullableById(id);

            if (existingMailingList == null)
            {
                Message = "Unable to locate mailing list.";
                return(this.RedirectToAction(a => a.Index(null)));
            }

            // check to make sure it's not a system mailing list
            if (_systemLists.Contains(mailinglist.Name))
            {
                Message = "Unable to edit system mailing list.";
                // redirect to index
                return(this.RedirectToAction(a => a.Index(mailinglist.Seminar.Id)));
            }

            // transfer values
            AutoMapper.Mapper.Map(mailinglist, existingMailingList);
            existingMailingList.Seminar = mailinglist.Seminar;

            // find the ones to delete
            var peopleToDelete = existingMailingList.People.Where(person => !mailinglist.People.Contains(person)).ToList();

            foreach (var person in peopleToDelete)
            {
                existingMailingList.People.Remove(person);
            }

            // add in the new ones
            var peopletoAdd = mailinglist.People.Where(a => !existingMailingList.People.Contains(a)).ToList();

            foreach (var person in peopletoAdd)
            {
                existingMailingList.People.Add(person);
            }

            if (ModelState.IsValid)
            {
                _mailinglistRepository.EnsurePersistent(existingMailingList);

                Message = "MailingList Edited Successfully";

                return(this.RedirectToAction(a => a.Index(mailinglist.Seminar != null ? mailinglist.Seminar.Id : (int?)null)));
            }

            var viewModel = MailingListViewModel.Create(RepositoryFactory, Site, mailinglist, mailinglist.Seminar != null ? mailinglist.Seminar.Id : (int?)null);

            return(View(viewModel));
        }
Esempio n. 3
0
        //
        // GET: /MailingList/Edit/5
        public ActionResult Edit(int id)
        {
            var mailinglist = _mailinglistRepository.GetNullableById(id);

            if (mailinglist == null)
            {
                Message = "Unable to locate mailing list.";
                return(RedirectToAction("Index"));
            }

            // check to make sure it's not a system mailing list
            if (_systemLists.Contains(mailinglist.Name))
            {
                Message = "Unable to edit system mailing list.";
                // redirect to index
                return(this.RedirectToAction(a => a.Index(mailinglist.Seminar.Id)));
            }

            var viewModel = MailingListViewModel.Create(RepositoryFactory, Site, mailinglist, mailinglist.Seminar != null ? mailinglist.Seminar.Id : (int?)null);

            return(View(viewModel));
        }
Esempio n. 4
0
        //
        // GET: /MailingList/Create
        public ActionResult Create(int?seminarId)
        {
            var viewModel = MailingListViewModel.Create(RepositoryFactory, Site, seminarId: seminarId);

            return(View(viewModel));
        }