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 Create(ApplicationEditModel applicationEditModel)
        {
            var applicationToCreate = new Application();

            Mapper.Map(applicationEditModel.Application, applicationToCreate);

            SetApplicationRoles(applicationToCreate, applicationEditModel.OrderedRoles, applicationEditModel.UnorderedRoles);

            applicationToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _applicationRepository.EnsurePersistent(applicationToCreate);

                Message = "Application Created Successfully";

                return(Json(new { success = true }));
            }
            else
            {
                var viewModel = ApplicationViewModel.Create(Repository);
                viewModel.Application = applicationEditModel.Application;

                return(View(viewModel));
            }
        }
        public ActionResult Create(ServiceMessage serviceMessage)
        {
            var serviceMessageToCreate = new ServiceMessage();

            TransferValues(serviceMessage, serviceMessageToCreate);

            if (ModelState.IsValid)
            {
                _serviceMessageRepository.EnsurePersistent(serviceMessageToCreate);

                // invalidate the cache
                System.Web.HttpContext.Current.Cache.Remove(CacheKey);

                Message = "ServiceMessage Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = ServiceMessageViewModel.Create(Repository);
                viewModel.ServiceMessage = serviceMessage;

                return(View(viewModel));
            }
        }
        public ActionResult Edit(ConditionalApprovalViewModel conditionalApprovalViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(conditionalApprovalViewModel));
            }

            ActionResult redirectToAction;
            var          conditionalApprovalToEdit = GetConditionalApprovalAndCheckAccess(conditionalApprovalViewModel.Id, out redirectToAction);

            if (conditionalApprovalToEdit == null)
            {
                return(redirectToAction);
            }

            //TODO: for now, only updating of the question is allowed
            conditionalApprovalToEdit.Question = conditionalApprovalViewModel.Question;

            _conditionalApprovalRepository.EnsurePersistent(conditionalApprovalToEdit);

            Message = "Conditional Approval edited successfully";

            if (conditionalApprovalToEdit.Workgroup != null)
            {
                return(this.RedirectToAction(a => a.ByWorkgroup(conditionalApprovalToEdit.Workgroup.Id)));
            }

            if (conditionalApprovalToEdit.Organization != null)
            {
                return(this.RedirectToAction(a => a.ByOrg(conditionalApprovalToEdit.Organization.Id)));
            }

            //return this.RedirectToAction(a => a.Index());
            return(this.RedirectToAction <ErrorController>(a => a.Index()));
        }
        public ActionResult Create(AutoApproval autoApproval, bool showAll = false)
        {
            autoApproval.Equal = !autoApproval.LessThan; //only one can be true, the other must be false
            autoApproval.User  = _userRepository.GetNullableById(CurrentUser.Identity.Name);
            ModelState.Clear();
            autoApproval.TransferValidationMessagesTo(ModelState);
            if (autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date)
            {
                ModelState.AddModelError("AutoApproval.Expiration", "Expiration date has already passed");
            }
            autoApproval.IsActive = true;

            if (ModelState.IsValid)
            {
                _autoApprovalRepository.EnsurePersistent(autoApproval);

                Message = "AutoApproval Created Successfully";
                if (autoApproval.Expiration.HasValue && autoApproval.Expiration.Value.Date <= DateTime.UtcNow.ToPacificTime().Date.AddDays(5))
                {
                    Message = Message + " Warning, will expire in 5 days or less";
                }
                return(this.RedirectToAction(a => a.Index(showAll)));
            }
            else
            {
                var viewModel = AutoApprovalViewModel.Create(Repository, CurrentUser.Identity.Name);
                viewModel.AutoApproval = autoApproval;
                ViewBag.ShowAll        = showAll;
                ViewBag.IsCreate       = true;

                return(View(viewModel));
            }
        }
Esempio n. 6
0
        public ActionResult Create(int seminarId, CaseStudy caseStudy, HttpPostedFileBase file)
        {
            var seminar = Repository.OfType <Seminar>().GetNullableById(seminarId);

            if (file != null)
            {
                var reader = new BinaryReader(file.InputStream);
                var data   = reader.ReadBytes(file.ContentLength);
                caseStudy.File        = data;
                caseStudy.ContentType = file.ContentType;
            }

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

            caseStudy.Seminar = seminar;

            ModelState.Clear();
            caseStudy.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _casestudyRepository.EnsurePersistent(caseStudy);
                Message = string.Format(Messages.Saved, "Case Study");
                return(this.RedirectToAction <SeminarController>(a => a.Edit(seminarId)));
            }

            var viewModel = CaseStudyViewModel.Create(Repository, seminar, caseStudy);

            return(View(viewModel));
        }
Esempio n. 7
0
        public ActionResult Create(AccessToken accessToken)
        {
            var accessTokenToCreate = new AccessToken();

            Mapper.Map(accessToken, accessTokenToCreate);

            accessTokenToCreate.SetNewToken();

            accessTokenToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _accessTokenRepository.EnsurePersistent(accessTokenToCreate);

                Message = "AccessToken Created Successfully";

                return(RedirectToAction("Details", new { id = accessTokenToCreate.Id }));
            }
            else
            {
                var viewModel = AccessTokenViewModel.Create(Repository);
                viewModel.AccessToken = accessToken;

                return(View(viewModel));
            }
        }
Esempio n. 8
0
        public ActionResult Create(Template template)
        {
            var templateToCreate = new Template();

            Mapper.Map(template, templateToCreate);
            templateToCreate.Seminar = SiteService.GetLatestSeminar(Site, true);

            ModelState.Clear();
            templateToCreate.TransferValidationMessagesTo(ModelState);
            if (ModelState.IsValid)
            {
                // inactivate all old templates
                foreach (var t in _templateRepository.Queryable.Where(a => a.NotificationType == templateToCreate.NotificationType))
                {
                    t.IsActive = false;
                    _templateRepository.EnsurePersistent(t);
                }

                _templateRepository.EnsurePersistent(templateToCreate);

                Message = "Template Created Successfully";

                return(RedirectToAction("Index"));
            }

            var viewModel = TemplateViewModel.Create(Repository, templateToCreate);

            return(View(viewModel));
        }
Esempio n. 9
0
        public void UpdateDefaultAccountApprover(Workgroup workgroup, bool isDefault, string selectedApprover, string roleId)
        {
            var existingApprover = _workgroupPermissionRepository.Queryable.SingleOrDefault(a => a.Workgroup == workgroup && a.Role.Id == roleId && a.IsDefaultForAccount);

            if (!isDefault)
            {
                if (existingApprover != null)
                {
                    existingApprover.IsDefaultForAccount = false;
                    _workgroupPermissionRepository.EnsurePersistent(existingApprover);
                }
            }
            else
            {
                if (existingApprover != null)
                {
                    if (existingApprover.User.Id != selectedApprover)
                    {
                        existingApprover.IsDefaultForAccount = false;
                        _workgroupPermissionRepository.EnsurePersistent(existingApprover);
                        var newApprover = _workgroupPermissionRepository.Queryable.Single(a => a.Workgroup == workgroup && a.Role.Id == roleId && !a.IsAdmin && a.User.Id == selectedApprover);
                        newApprover.IsDefaultForAccount = true;
                        _workgroupPermissionRepository.EnsurePersistent(newApprover);
                    }
                }
                else
                {
                    var newApprover = _workgroupPermissionRepository.Queryable.Single(a => a.Workgroup == workgroup && a.Role.Id == roleId && !a.IsAdmin && a.User.Id == selectedApprover);
                    newApprover.IsDefaultForAccount = true;
                    _workgroupPermissionRepository.EnsurePersistent(newApprover);
                }
            }
        }
Esempio n. 10
0
        public void AddToMailingList(Seminar seminar, Person person, string mailingListName)
        {
            var mailingList = seminar.MailingLists.FirstOrDefault(a => a.Name == mailingListName);

            if (mailingList != null)
            {
                mailingList.AddPerson(person);

                _mailingListRepository.EnsurePersistent(mailingList);
            }
        }
Esempio n. 11
0
        public ActionResult Decide(int id, bool isApproved, string reason)
        {
            var application = _applicationRepository.GetNullableById(id);

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

            // make the changes to the object
            application.IsPending      = false;
            application.IsApproved     = isApproved;
            application.DateDecision   = DateTime.Now;
            application.DecisionReason = reason;

            application.TransferValidationMessagesTo(ModelState);

            Person person = null;

            if (ModelState.IsValid)
            {
                person = _personService.CreateSeminarPerson(application, ModelState);
            }

            if (person == null)
            {
                ModelState.AddModelError("Person", "Unsuccessful in adding person to the current seminar.");
            }

            // check if model state is still valid, might have changed on create
            if (ModelState.IsValid)
            {
                // save the application
                _applicationRepository.EnsurePersistent(application);
                Message = string.Format("Application for {0} has been {1}", application.FullName, isApproved ? "Approved" : "Denied");

                if (isApproved)
                {
                    _eventService.Accepted(person, Site);
                }
                else
                {
                    _eventService.Denied(person, Site);
                }

                return(this.RedirectToAction <SeminarApplicationController>(a => a.Index()));
            }

            return(View(application));
        }
Esempio n. 12
0
        public ActionResult AddNote(int id, InformationRequestNote informationRequestNote)
        {
            var informationRequest = _informationrequestRepository.GetNullableById(id);

            if (informationRequest == null)
            {
                Message = string.Format(Messages.NotFound, "information request", id);
                return(this.RedirectToAction(a => a.Index()));
            }

            ModelState.Clear();

            var irn = new InformationRequestNote(informationRequest, informationRequestNote.Notes, CurrentUser.Identity.Name);

            irn.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _informationRequestNoteRepository.EnsurePersistent(irn);

                Message = string.Format(Messages.Saved, "Note");
                return(this.RedirectToAction(a => a.Edit(id)));
            }


            return(View(irn));
        }
Esempio n. 13
0
        public ActionResult MoreInformation([Bind(Exclude = "Site")] InformationRequest informationRequest)
        {
            ModelState.Clear();

            informationRequest.Site    = SiteService.LoadSite(Site);
            informationRequest.Seminar = SiteService.GetLatestSeminar(Site);
            informationRequest.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _informationRequestRepository.EnsurePersistent(informationRequest);
                Message = string.Format("Your request for information has been submitted.");

                // send the information request notification to admin
                _notificationService.SendInformationRequestNotification(informationRequest, informationRequest.Site);

                // queue an email for the person requesting information
                _notificationService.SendInformationRequestConfirmatinon(informationRequest.Email, informationRequest.Site);

                return(this.RedirectToAction <HomeController>(a => a.Index()));
            }

            ViewBag.Countries = RepositoryFactory.CountryRepository.Queryable.OrderBy(a => a.Name).ToList();
            return(View(informationRequest));
        }
        public JsonResult SaveAttachment()
        {
            try
            {
                var request     = ControllerContext.HttpContext.Request;
                var fileName    = request["qqfile"];
                var contentType = request.Headers["X-File-Type"];

                byte[] contents;

                using (var reader = new BinaryReader(request.InputStream))
                {
                    contents = reader.ReadBytes((int)request.InputStream.Length);
                }

                // save the attachment
                var attachment = new Attachment()
                {
                    Contents = contents, ContentType = contentType, FileName = fileName
                };
                _attachmentRepository.EnsurePersistent(attachment);

                return(Json(new { id = attachment.Id, fileName = fileName, success = true }));
            }
            catch (Exception)
            {
                return(Json(false));
            }

            return(Json(false));
        }
Esempio n. 15
0
        public ActionResult Create(Role role)
        {
            var roleToCreate = new Role {
                Name = role.Name
            };

            //Make sure role name is not already in active use
            var existingActiveRoleName = _roleRepository
                                         .Queryable
                                         .Where(x => x.Name == role.Name && x.Inactive == false)
                                         .Any();

            if (existingActiveRoleName)
            {
                ModelState.AddModelError("Role.Name", "The rolename given already exists and is active");
            }

            roleToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _roleRepository.EnsurePersistent(roleToCreate);

                Message = "Role Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = RoleViewModel.Create(Repository);
                viewModel.Role = role;

                return(View(viewModel));
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Insert a new user into the database
        /// </summary>
        private void InsertNewUser(User user)
        {
            //Make sure the user given in valid
            Check.Require(user.IsValid(), string.Format("User not valid: {0}", string.Join(", ", user.ValidationResults().Select(x => x.Message))));

            _userRepository.EnsurePersistent(user);
        }
        public JsonResult AddAssociation(int userId, int applicationId, int unitId)
        {
            //Now make sure the user doesn't already have this unit association
            var userHasUnitAssociation = (from u in _unitAssociationRepository.Queryable
                                          where u.Application.Id == applicationId &&
                                          u.Unit.Id == unitId &&
                                          u.User.Id == userId
                                          select u).Any();

            if (userHasUnitAssociation)
            {
                return(Json(new JsonStatusModel(success: false)
                {
                    Comment = "User already has this unit association"
                }));
            }

            var newUnitAssociation = new UnitAssociation()
            {
                Application = Repository.OfType <Application>().GetById(applicationId),
                Unit        = Repository.OfType <Unit>().GetById(unitId),
                User        = Repository.OfType <User>().GetById(userId)
            };

            _unitAssociationRepository.EnsurePersistent(newUnitAssociation);

            return(Json(new JsonStatusModel(success: true)
            {
                Identifier = newUnitAssociation.Id
            }));
        }
Esempio n. 18
0
        public static void LoadDomainDataUsers(IRepository<User> userRepository)
        {
            string[] names = { "Scott", "John", "James", "Bob", "Larry", "Joe", "Pete", "Adam", "Alan", "Ken" };
            string[] loginIDs = { "postit", "aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee", "fffff", "ggggg", "hhhhh", "iiiii" };

            //using (var ts = new TransactionScope())
            //{
            NHibernateSessionManager.Instance.BeginTransaction();
            for (int i = 0; i < 10; i++)
            {
                var user = new User
                {
                    Email = "*****@*****.**",
                    EmployeeID = "999999999",
                    FirstName = names[i],
                    LastName = "Last",
                    LoginID = loginIDs[i],
                    UserKey = Guid.NewGuid()
                };

                userRepository.EnsurePersistent(user); //Save
            }

            NHibernateSessionManager.Instance.CommitTransaction();
        }
        /// <summary>
        /// Creates the users for DB Tests.
        /// </summary>
        private void CreateUsers()
        {
            string[] names    = { "Scott", "John", "James", "Bob", "Larry", "Joe", "Pete", "Adam", "Alan", "Ken" };
            string[] loginIDs = { "postit", "aaaaa", "bbbbb", "ccccc", "ddddd", "eeeee", "fffff", "ggggg", "hhhhh", "iiiii" };

            //using (var ts = new TransactionScope())
            //{
            NHibernateSessionManager.Instance.BeginTransaction();
            for (int i = 0; i < 10; i++)
            {
                var user = new User
                {
                    Email      = "*****@*****.**",
                    EmployeeID = "999999999",
                    FirstName  = names[i],
                    LastName   = "Last",
                    LoginID    = loginIDs[i],
                    UserKey    = Guid.NewGuid()
                };

                _userRepository.EnsurePersistent(user); //Save
            }

            NHibernateSessionManager.Instance.CommitTransaction();
        }
Esempio n. 20
0
        public void CanSaveValidUnitUsingGenericRepository()
        {
            var unit = CreateValidUnit();

            Assert.AreEqual(true, unit.IsTransient());

            _repository.EnsurePersistent(unit);

            Assert.AreEqual(false, unit.IsTransient());
        }
        public ActionResult Create(string id, CustomField customField)
        {
            var org = string.IsNullOrWhiteSpace(id) ? null : _organizationRepository.GetNullableById(id);

            if (org == null)
            {
                Message = "Organization not found for custom field.";
                return(this.RedirectToAction <OrganizationController>(a => a.Index()));
            }

            var message = string.Empty;

            if (!_securityService.HasWorkgroupOrOrganizationAccess(null, org, out message))
            {
                Message = message;
                return(this.RedirectToAction <ErrorController>(a => a.NotAuthorized()));
            }

            var customFieldToCreate = new CustomField();

            customFieldToCreate.Organization = org;

            TransferValues(customField, customFieldToCreate);

            ModelState.Clear();
            customFieldToCreate.TransferValidationMessagesTo(ModelState);

            if (ModelState.IsValid)
            {
                _customFieldRepository.EnsurePersistent(customFieldToCreate);

                Message = "CustomField Created Successfully";

                //return RedirectToAction("Index", new {id=id});
                return(this.RedirectToAction(a => a.Index(id)));
            }
            else
            {
                var viewModel = CustomFieldViewModel.Create(Repository, org);
                viewModel.CustomField = customField;

                return(View(viewModel));
            }
        }
Esempio n. 22
0
        public ActionResult Index()
        {
            try
            {
                var seminar = SiteService.GetLatestSeminar(Site);

                if (seminar.RegistrationId.HasValue)
                {
                    var result = _registrationService.RefreshAllRegistration(seminar.RegistrationId.Value);

                    // load all of the seminar people
                    var seminarPeople = seminar.SeminarPeople;

                    foreach (var sp in seminarPeople)
                    {
                        var reg = result.FirstOrDefault(a => a.ReferenceId == sp.ReferenceId);

                        if (reg != null)
                        {
                            sp.TransactionId = reg.TransactionId;
                            sp.Paid          = reg.Paid;

                            // remove from the payment reminder mailing lists
                            if (sp.Paid)
                            {
                                _notificationService.RemoveFromMailingList(sp.Seminar, sp.Person, MailingLists.PaymentReminder);
                                _notificationService.RemoveFromMailingList(sp.Seminar, sp.Person, MailingLists.Registered);
                                _notificationService.AddToMailingList(sp.Seminar, sp.Person, MailingLists.Attending);
                            }

                            _seminarPersonRepository.EnsurePersistent(sp);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var client  = new SmtpClient("smtp.ucdavis.edu");
                var message = new MailMessage("*****@*****.**", "*****@*****.**");
                message.Subject = "Error Syncing from Agribusiness";
                message.Body    = ex.Message;
                client.Send(message);
            }

            //if (ConfigurationManager.AppSettings["SyncCall"] == "true")
            //{
            //    // determine the address of the calling person.
            //    var client = new SmtpClient("smtp.ucdavis.edu");
            //    var message = new MailMessage("*****@*****.**", "*****@*****.**");
            //    message.Subject = "sync call was made to agribusiness and completed";
            //    message.Body = Request.UserHostAddress ?? "No address";
            //    client.Send(message);
            //}

            return(View());
        }
        public void CanSaveValidUnitAssociationUsingGenericRepository()
        {
            var newUnitAssociation = CreateValidUnitAssociation();

            Assert.AreEqual(true, newUnitAssociation.IsTransient());

            _unitAssociationRepository.EnsurePersistent(newUnitAssociation);

            Assert.AreEqual(false, newUnitAssociation.IsTransient());
        }
Esempio n. 24
0
 /// <summary>
 /// Loads the records for CRUD Tests.
 /// </summary>
 /// <returns></returns>
 protected virtual void LoadRecords(int entriesToAdd)
 {
     EntriesAdded += entriesToAdd;
     for (int i = 0; i < entriesToAdd; i++)
     {
         var validEntity = GetValid(i + 1);
         if (typeof(IdT) == typeof(int))
         {
             _intRepository.EnsurePersistent(validEntity);
         }
         else if (typeof(IdT) == typeof(Guid))
         {
             _guidRepository.EnsurePersistent(validEntity, true);
         }
         else
         {
             _stringRepository.EnsurePersistent(validEntity);
         }
     }
 }
Esempio n. 25
0
        public ActionResult CreatePerson(int id, PersonEditModel personEditModel, HttpPostedFileBase profilepic)
        {
            ModelState.Clear();

            var person = personEditModel.Person;

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

            person.User = user;

            SeminarPerson seminarPerson = null;

            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)
                {
                    person.AddSite(SiteService.LoadSite(Site));

                    // we're good save the person object
                    _personRepository.EnsurePersistent(person);
                    Message = string.Format(Messages.Saved, "Person");

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

                    return(this.RedirectToAction <PersonController>(a => a.AdminEdit(person.User.Id, null, true)));
                }

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

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

            viewModel.Addresses = personEditModel.Addresses;
            viewModel.UserName  = personEditModel.UserName;
            return(View(viewModel));
        }
Esempio n. 26
0
        public ActionResult AdminEdit(Guid id, int?seminarId, bool?allList, PersonEditModel personEditModel, HttpPostedFileBase profilepic)
        {
            var user = _userRepository.GetNullableById(id);

            if (user == null)
            {
                Message = string.Format(Messages.NotFound, "user", id);
                int sid = 0;

                if (!seminarId.HasValue)
                {
                    sid = SiteService.GetLatestSeminar(Site).Id;
                }
                else
                {
                    sid = seminarId.Value;
                }

                return(this.RedirectToAction <AttendeeController>(a => a.Index(sid)));
            }

            var seminarPerson = _seminarPersonRepository.GetNullableById(personEditModel.SeminarPersonId);
            var person        = SetPerson(personEditModel, seminarPerson, ModelState, user.Person, profilepic);

            var membership = user.Membership;

            user.SetUserName(personEditModel.UserName);
            membership.SetEmail(personEditModel.Email);

            if (ModelState.IsValid)
            {
                _personRepository.EnsurePersistent(person);
                _userRepository.EnsurePersistent(user);
                _membershipRepository.EnsurePersistent(membership);

                if (seminarPerson != null)
                {
                    _seminarPersonRepository.EnsurePersistent(seminarPerson);
                }
                Message = string.Format(Messages.Saved, "Person");

                // send to crop photo if one was uploaded
                if (profilepic != null)
                {
                    return(this.RedirectToAction(a => a.UpdateProfilePicture(person.Id, seminarId, true)));
                }

                return(this.RedirectToAction(a => a.AdminEdit(person.User.Id, seminarId, null)));
            }

            ViewBag.AllList = allList ?? false;
            var viewModel = AdminPersonViewModel.Create(Repository, _firmService, Site, seminarId, user.Person, user.Email);

            return(View(viewModel));
        }
Esempio n. 27
0
        public ActionResult UpdateAllRegistrations(int id)
        {
            var seminar = _seminarRespository.GetNullableById(id);

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

            // make the remote call
            var result = _registrationService.RefreshAllRegistration(seminar.RegistrationId.Value);

            // load all of the seminar people
            var seminarPeople = seminar.SeminarPeople;

            foreach (var sp in seminarPeople)
            {
                var reg = result.Where(a => a.ReferenceId == sp.ReferenceId).FirstOrDefault();

                if (reg != null)
                {
                    sp.TransactionId = reg.TransactionId;
                    sp.Paid          = reg.Paid;

                    // remove from the payment reminder mailing lists
                    if (sp.Paid)
                    {
                        _notificationService.RemoveFromMailingList(sp.Seminar, sp.Person, MailingLists.PaymentReminder);
                        _notificationService.RemoveFromMailingList(sp.Seminar, sp.Person, MailingLists.Registered);
                        _notificationService.AddToMailingList(sp.Seminar, sp.Person, MailingLists.Attending);
                    }

                    _seminarPersonRepository.EnsurePersistent(sp);
                }
            }

            Message = "Registration status' for all attendees have been updated.";
            return(this.RedirectToAction(a => a.Index(id)));
        }
Esempio n. 28
0
        public ActionResult Create(Commodity commodity)
        {
            var commodityToCreate = new Commodity();

            TransferValues(commodity, commodityToCreate);

            if (ModelState.IsValid)
            {
                _commodityRepository.EnsurePersistent(commodityToCreate);

                Message = "Commodity Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = CommodityViewModel.Create(Repository);
                viewModel.Commodity = commodity;

                return(View(viewModel));
            }
        }
Esempio n. 29
0
        public ActionResult Create(Order order)
        {
            if (ModelState.IsValid)
            {
                _orderRepository.EnsurePersistent(order);

                _messageFactory.SendNewOrderMessage();

                Message = "New Order Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                _orderRepository.DbContext.RollbackTransaction();

                var viewModel = OrderViewModel.Create(Repository.OfType <Customer>());
                viewModel.Order = order;

                return(View(viewModel));
            }
        }
Esempio n. 30
0
        public ActionResult Create(SalaryScale salaryScale)
        {
            var salaryScaleToCreate = new SalaryScale();

            TransferValues(salaryScale, salaryScaleToCreate);

            if (ModelState.IsValid)
            {
                _salaryScaleRepository.EnsurePersistent(salaryScaleToCreate);

                Message = "SalaryScale Created Successfully";

                return(RedirectToAction("Index"));
            }
            else
            {
                var viewModel = SalaryScaleViewModel.Create(Repository);
                viewModel.SalaryScale = salaryScale;

                return(View(viewModel));
            }
        }
        /// <summary>
        /// Creates 5 units for DB Tests.
        /// </summary>
        private void CreateUnits()
        {
            NHibernateSessionManager.Instance.BeginTransaction();
            for (int i = 1; i <= 5; i++)
            {
                var unit = CreateValidUnit();
                unit.FullName  += i.ToString();
                unit.ShortName += i.ToString();

                _unitRepository.EnsurePersistent(unit); //Save
            }
            NHibernateSessionManager.Instance.CommitTransaction();
        }
Esempio n. 32
0
        /// <summary>
        /// Creates the accounts.
        /// </summary>
        /// <param name="accountRepository">The account repository.</param>
        private static void CreateAccounts(IRepository<Account> accountRepository)
        {
            //Create 2 active accounts, 3 inactive
            for (int i = 1; i < 6; i++)
            {
                var account = new Account
                                  {
                                      Name = "Account" + i,
                                  };
                account.IsActive = i%2==0;

                accountRepository.EnsurePersistent(account);
            }
        }