Ejemplo n.º 1
0
        public long EditUser(UserModel model)
        {
            Contract.Assert(model.UserId.HasValue);

            var user = this.Manager.Load(model.UserId.Value);
            var role = this.RoleManager.Load(model.RoleId);

            PartnerEntity partner = null;
            if (model.PartnerId.HasValue)
            {
                partner = this.PartnerManager.Load(model.PartnerId.Value);
            }

            user.Name = model.Name;
            user.Email = model.Email;
            user.UserPasswordCredential.Login = model.Login;
            user.Role = role;
            user.Partner = partner;

            using (var tx = new Transaction())
            {
                this.Manager.Update(user);

                tx.Complete();
            }

            return user.Id;
        }
Ejemplo n.º 2
0
        public long CreateUser(UserModel model)
        {
            PartnerEntity partner = null;
            if (model.PartnerId.HasValue)
            {
                partner = this.PartnerManager.Load(model.PartnerId.Value);
            }

            var role = this.RoleManager.Load(model.RoleId);

            var user = new UserEntity
                {
                    Name = model.Name,
                    Email = model.Email,
                    Partner = partner,
                    Role = role
                };

            this.Manager.Create(user, model.Login, model.Password);

            return user.Id;
        }
Ejemplo n.º 3
0
        public void FillUserModel(UserModel model)
        {
            var partners = this.PartnerManager.FindAll(new PartnerAll());
            var roles = this.RoleManager.FindAll(new RoleAll());

            model.AvailablePartners = partners.ToDictionary(p => p.Id, p => p.Name);
            model.AvailableRoles = roles.ToDictionary(p => p.Id, p => p.Name);
        }
Ejemplo n.º 4
0
        public UserModel GetEditModel(long id)
        {
            var user = this.Manager.Load(id);

            var model = new UserModel
                {
                    UserId = user.Id,
                    Name = user.Name,
                    Email = user.Email,
                    Login = user.UserPasswordCredential != null ? user.UserPasswordCredential.Login : string.Empty,
                    PartnerId = user.Partner != null ? user.Partner.Id : (long?)null,
                    RoleId = user.Role.Id
                };

            this.FillUserModel(model);

            return model;
        }
Ejemplo n.º 5
0
        public UserModel GetCreateModel()
        {
            var model = new UserModel();

            this.FillUserModel(model);

            return model;
        }