Пример #1
0
        public Person CreateSeminarPerson(Application application, ModelStateDictionary modelState)
        {
            var person = SetPerson(application, application.User.Person);

            var firm = application.Firm ?? new Firm(application.FirmName, !string.IsNullOrWhiteSpace(application.FirmDescription)? application.FirmDescription : "n/a");

            var seminarPerson = new SeminarPerson()
            {
                Seminar = application.Seminar,
                Title = application.JobTitle,
                Firm = firm,
                Commodities = new List<Commodity>(application.Commodities),
                FirmType = application.FirmType,
                OtherFirmType = application.OtherFirmType
            };

            if (!string.IsNullOrWhiteSpace(application.OtherCommodity))
            {
                // transfer "other" commodities
                var others = application.OtherCommodity.Split(',');
                if (others.Count() > 0)
                {
                    foreach (var com in others)
                    {
                        var existing = _commodityRepository.Queryable.Where(a => a.Name == com).FirstOrDefault();

                        // check for an existing commodity
                        if (existing != null)
                        {
                            // assign that commodity if it exists
                            seminarPerson.Commodities.Add(existing);
                        }
                        else
                        {
                            // otherwise create a new one
                            var newcom = new Commodity() { IsActive = false, Name = com };
                            seminarPerson.Commodities.Add(newcom);
                        }
                    }
                }
            }

            person.AddSeminarPerson(seminarPerson);

            UpdateAddress(person, application);

            UpdateAssistant(person, application);

            person.TransferValidationMessagesTo(modelState);
            seminarPerson.TransferValidationMessagesTo(modelState);

            if (modelState.IsValid)
            {
                _firmRepository.EnsurePersistent(firm);
                _personRepository.EnsurePersistent(person);
                _seminarPersonRepository.EnsurePersistent(seminarPerson);

                return person;
            }

            return null;
        }
Пример #2
0
        public ActionResult Create(int?id, PersonEditModel personEditModel, HttpPostedFileBase profilepic)
        {
            ModelState.Clear();

            var seminar = _seminarRepository.GetNullableById(id.HasValue ? id.Value : 0);

            var person = personEditModel.Person;

            var user = _userRepository.Queryable.FirstOrDefault(a => a.LoweredUserName == personEditModel.UserName.ToLower());

            person.User = user;
            person.AddSite(SiteService.LoadSite(Site));

            SeminarPerson seminarPerson = null;

            if (seminar != null)
            {
                seminarPerson = new SeminarPerson(seminar, person)
                {
                    Invite = true, Title = personEditModel.Title
                };
                person.AddSeminarPerson(seminarPerson);
                seminarPerson.TransferValidationMessagesTo(ModelState);
            }

            person = SetPerson(personEditModel, seminarPerson, ModelState, person, profilepic);

            ModelState.Remove("Person.User");

            if (ModelState.IsValid)
            {
                // try to create the user
                var createStatus = _membershipService.CreateUser(personEditModel.UserName
                                                                 , Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 10)
                                                                 , personEditModel.Email);

                // retrieve the user to assign
                var createdUser = _userRepository.Queryable.FirstOrDefault(a => a.LoweredUserName == personEditModel.UserName.ToLower());
                person.User = createdUser;

                // save only if user creation was successful
                if (createStatus == MembershipCreateStatus.Success)
                {
                    // we're good save the person object
                    _personRepository.EnsurePersistent(person);
                    Message = string.Format(Messages.Saved, "Person");

                    if (person.OriginalPicture != null)
                    {
                        return(this.RedirectToAction(a => a.UpdateProfilePicture(person.Id, null, false)));
                    }
                    else
                    {
                        return(this.RedirectToAction(a => a.AdminEdit(createdUser.Id, null, null)));
                    }
                }

                ModelState.AddModelError("Create User", AccountValidation.ErrorCodeToString(createStatus));
            }

            ViewData["site"] = Site;

            var viewModel = PersonViewModel.Create(Repository, _firmService, Site, seminar, person, personEditModel.Email);

            viewModel.Addresses = personEditModel.Addresses;
            viewModel.UserName  = personEditModel.UserName;
            return(View(viewModel));
        }
Пример #3
0
        public ActionResult AddConfirm(int id, int personId, SeminarPerson seminarPerson, Firm firm)
        {
            var seminar = _seminarRespository.GetNullableById(id);

            if (seminar == null)
            {
                Message = string.Format(Messages.NotFound, "Seminar", id);
                return(this.RedirectToAction <SeminarController>(a => a.Index()));
            }

            var person = _personRepository.GetNullableById(personId);

            if (person == null)
            {
                Message = string.Format(Messages.NotFound, "person", personId);
                return(this.RedirectToAction(a => a.Add(id)));
            }

            if (firm.Id > 0)
            {
                seminarPerson.Firm = _firmRepository.GetNullableById(firm.Id);
            }
            else if (firm.Id == 0)
            {
                seminarPerson.Firm = firm;
            }

            // fill in the values
            seminarPerson.Person  = person;
            seminarPerson.Seminar = seminar;

            ModelState.Clear();
            seminarPerson.TransferValidationMessagesTo(ModelState);

            if (seminarPerson.Firm != null)
            {
                seminarPerson.Firm.TransferValidationMessagesTo(ModelState);
            }

            if (ModelState.IsValid)
            {
                _seminarPersonRepository.EnsurePersistent(seminarPerson);
                Message = string.Format("{0} has been added to the {1} seminar.", person.FullName, seminar.Year);

                _notificationService.AddToMailingList(seminar, person, MailingLists.Registered);

                // add user to the reminder emails
                _notificationService.AddToMailingList(seminar, person, MailingLists.PaymentReminder);
                _notificationService.AddToMailingList(seminar, person, MailingLists.HotelReminder);

                if (string.IsNullOrWhiteSpace(person.Biography))
                {
                    _notificationService.AddToMailingList(seminar, person, MailingLists.BioReminder);
                }
                if (person.OriginalPicture == null)
                {
                    _notificationService.AddToMailingList(seminar, person, MailingLists.PhotoReminder);
                }

                return(this.RedirectToAction(a => a.Add(id)));
            }

            var viewModel = AddConfirmViewModel.Create(Repository, _firmService, seminar, person, seminarPerson, seminarPerson.Firm);

            return(View(viewModel));
        }
Пример #4
0
        public ActionResult Create(int? id, PersonEditModel personEditModel, HttpPostedFileBase profilepic)
        {
            ModelState.Clear();

            var seminar = _seminarRepository.GetNullableById(id.HasValue ? id.Value : 0);

            var person = personEditModel.Person;

            var user = _userRepository.Queryable.FirstOrDefault(a => a.LoweredUserName == personEditModel.UserName.ToLower());
            person.User = user;
            person.AddSite(SiteService.LoadSite(Site));

            SeminarPerson seminarPerson = null;
            if (seminar != null)
            {
                seminarPerson = new SeminarPerson(seminar, person) { Invite = true, Title = personEditModel.Title };
                person.AddSeminarPerson(seminarPerson);
                seminarPerson.TransferValidationMessagesTo(ModelState);
            }

            person = SetPerson(personEditModel, seminarPerson, ModelState, person, profilepic);

            ModelState.Remove("Person.User");

            if (ModelState.IsValid)
            {

                // try to create the user
                var createStatus = _membershipService.CreateUser(personEditModel.UserName
                                              , Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 10)
                                              , personEditModel.Email);

                // retrieve the user to assign
                var createdUser = _userRepository.Queryable.FirstOrDefault(a => a.LoweredUserName == personEditModel.UserName.ToLower());
                person.User = createdUser;

                // save only if user creation was successful
                if (createStatus == MembershipCreateStatus.Success)
                {
                    // we're good save the person object
                    _personRepository.EnsurePersistent(person);
                    Message = string.Format(Messages.Saved, "Person");

                    if (person.OriginalPicture != null) return this.RedirectToAction(a => a.UpdateProfilePicture(person.Id, null, false));
                    else return this.RedirectToAction(a => a.AdminEdit(createdUser.Id, null, null));
                }

                ModelState.AddModelError("Create User", AccountValidation.ErrorCodeToString(createStatus));
            }

            ViewData["site"] = Site;

            var viewModel = PersonViewModel.Create(Repository, _firmService, Site, seminar, person, personEditModel.Email);
            viewModel.Addresses = personEditModel.Addresses;
            viewModel.UserName = personEditModel.UserName;
            return View(viewModel);
        }
Пример #5
0
        public ActionResult AddConfirm(int id, int personId, SeminarPerson seminarPerson, Firm firm)
        {
            var seminar = _seminarRespository.GetNullableById(id);

            if (seminar == null)
            {
                Message = string.Format(Messages.NotFound, "Seminar", id);
                return this.RedirectToAction<SeminarController>(a => a.Index());
            }

            var person = _personRepository.GetNullableById(personId);

            if (person == null)
            {
                Message = string.Format(Messages.NotFound, "person", personId);
                return this.RedirectToAction(a => a.Add(id));
            }

            if (firm.Id > 0)
            {
                seminarPerson.Firm = _firmRepository.GetNullableById(firm.Id);
            }
            else if (firm.Id == 0)
            {
                seminarPerson.Firm = firm;
            }

            // fill in the values
            seminarPerson.Person = person;
            seminarPerson.Seminar = seminar;

            ModelState.Clear();
            seminarPerson.TransferValidationMessagesTo(ModelState);

            if (seminarPerson.Firm != null)
            {
                seminarPerson.Firm.TransferValidationMessagesTo(ModelState);
            }

            if (ModelState.IsValid)
            {
                _seminarPersonRepository.EnsurePersistent(seminarPerson);
                Message = string.Format("{0} has been added to the {1} seminar.", person.FullName, seminar.Year);

                _notificationService.AddToMailingList(seminar, person, MailingLists.Registered);

                // add user to the reminder emails
                _notificationService.AddToMailingList(seminar, person, MailingLists.PaymentReminder);
                _notificationService.AddToMailingList(seminar, person, MailingLists.HotelReminder);

                if (string.IsNullOrWhiteSpace(person.Biography)) _notificationService.AddToMailingList(seminar, person, MailingLists.BioReminder);
                if (person.OriginalPicture == null) _notificationService.AddToMailingList(seminar, person, MailingLists.PhotoReminder);

                return this.RedirectToAction(a => a.Add(id));
            }

            var viewModel = AddConfirmViewModel.Create(Repository, _firmService, seminar, person, seminarPerson, seminarPerson.Firm);
            return View(viewModel);
        }
Пример #6
0
        public Person CreateSeminarPerson(Application application, ModelStateDictionary modelState)
        {
            var person = SetPerson(application, application.User.Person);

            var firm = application.Firm ?? new Firm(application.FirmName, !string.IsNullOrWhiteSpace(application.FirmDescription)? application.FirmDescription : "n/a");

            var seminarPerson = new SeminarPerson()
            {
                Seminar       = application.Seminar,
                Title         = application.JobTitle,
                Firm          = firm,
                Commodities   = new List <Commodity>(application.Commodities),
                FirmType      = application.FirmType,
                OtherFirmType = application.OtherFirmType
            };

            if (!string.IsNullOrWhiteSpace(application.OtherCommodity))
            {
                // transfer "other" commodities
                var others = application.OtherCommodity.Split(',');
                if (others.Count() > 0)
                {
                    foreach (var com in others)
                    {
                        var existing = _commodityRepository.Queryable.Where(a => a.Name == com).FirstOrDefault();

                        // check for an existing commodity
                        if (existing != null)
                        {
                            // assign that commodity if it exists
                            seminarPerson.Commodities.Add(existing);
                        }
                        else
                        {
                            // otherwise create a new one
                            var newcom = new Commodity()
                            {
                                IsActive = false, Name = com
                            };
                            seminarPerson.Commodities.Add(newcom);
                        }
                    }
                }
            }


            person.AddSeminarPerson(seminarPerson);

            UpdateAddress(person, application);

            UpdateAssistant(person, application);

            person.TransferValidationMessagesTo(modelState);
            seminarPerson.TransferValidationMessagesTo(modelState);

            if (modelState.IsValid)
            {
                _firmRepository.EnsurePersistent(firm);
                _personRepository.EnsurePersistent(person);
                _seminarPersonRepository.EnsurePersistent(seminarPerson);

                return(person);
            }

            return(null);
        }