Exemplo n.º 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try {
                var promoter = new Promoter {
                    Name  = model.Name,
                    Login = ""
                };
                DbSession.Save(promoter);
                promoter.Login = promoter.Id.ToString();
                DbSession.Flush();
                model.Login = promoter.Login;

                model.Password = GeneratePassword();
                CreateUserInAD(Promoter.ACC_LOGIN_PREFIX + promoter.Login, model.Password);

                Association association;
                if (model.CreateAssociation)
                {
                    association = new Association {
                        Name = model.Name
                    };
                    DbSession.Save(association);
                    DbSession.Flush();
                }
                else
                {
                    association = DbSession.Query <Association>().First(r => r.Id == model.AssociationId);
                }
                var promoterAssociation = new PromoterAssociation {
                    Association = association,
                    Promoter    = promoter
                };
                DbSession.Save(promoterAssociation);
            }
            catch (Exception ex) {
                DbSession.Transaction.Rollback();
#if !DEBUG
                Membership.DeleteUser(Promoter.ACC_LOGIN_PREFIX + model.Login);
#endif
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }

            return(View("Confirm", model));
        }
Exemplo n.º 2
0
        public static Association AddAssociation(ISession dbSession, Promoter promoter)
        {
            var newItem = new Association {
                Name = "new Association"
            };

            dbSession.Save(newItem);
            var link = new PromoterAssociation {
                Association = newItem,
                Promoter    = promoter
            };

            dbSession.Save(link);
            newItem.Promoters.Add(link);
            return(newItem);
        }