Esempio n. 1
0
        public MessageResultDto UpdateGroup(Guid id, string name)
        {
            var result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    IRepository <Group> groupRepository = new Repository <Group>(session);
                    var existingGroup = groupRepository.FindOne(x => x.Id != id, new Tuple <Expression <Func <Group, object> >, string>(x => x.Name, name));


                    if (null == existingGroup)
                    {
                        var group = groupRepository.FindOne(x => x.Id == id);
                        group.Name = name;
                        groupRepository.Update(group);
                        transaction.Commit();
                        result.SuccessMessage("Group updated successfully", group.Id);
                    }
                    else
                    {
                        result.ErrorMessage("Group with same name already exisits");
                    }
                }
            return(result);
        }
Esempio n. 2
0
        public MessageResultDto AddGroup(string name)
        {
            Group group  = null;
            var   result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    IRepository <Group> groupRepository = new Repository <Group>(session);
                    var existingGroup = groupRepository.FindOne(new Tuple <Expression <Func <Group, object> >, string>(x => x.Name, name));

                    if (null == existingGroup)
                    {
                        group = new Group {
                            Name = name
                        };
                        groupRepository.Add(group);
                        transaction.Commit();
                        result.SuccessMessage("Group added successfully", group.Id);
                    }
                    else
                    {
                        result.ErrorMessage("Group with same name already exisits");
                    }
                }
            return(result);
        }
Esempio n. 3
0
        public MessageResultDto AddUser(string firstname, string lastname, string nickname, string username, Guid groupId)
        {
            User user;
            var  result = new MessageResultDto();

            using (ISession session = _sessionFactory.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    IRepository <Group> groupRepository = new Repository <Group>(session);
                    var group = groupRepository.FindOne(x => x.Id == groupId);

                    IRepository <User> userRepository = new Repository <User>(session);
                    var existingUser = userRepository.FindOne(new Tuple <Expression <Func <User, object> >, string>(x => x.Username, username));

                    if (null == existingUser)
                    {
                        user = new User
                        {
                            FirstName = firstname,
                            LastName  = lastname,
                            Nickname  = nickname,
                            Username  = username,
                            Password  = Constants.DEFAULT_PASSWORD,
                            Group     = group
                        };
                        userRepository.Add(user);
                        transaction.Commit();
                        result.SuccessMessage("User added successfully", user.Id);
                    }
                    else
                    {
                        result.ErrorMessage("User with same username already exists");
                    }
                }
            return(result);
        }