public User AddUser(string firstName, string lastName, bool isActive, string email, Dictionary<int, bool> customActions, List<long> groups,string userName)
        {
            try
            {
                using (var scope = new TransactionScope())
                {
                    var u = new User(0, firstName, lastName, email,"", userName);
                    //assignCustomActionsToParty(u,customActions);
                    //assignUserGroupsToUser(u,groups);
                    //_userRepository.Add(u);
                    //scope.Complete();
                    return u;

                }
            }
            catch (Exception exp)
            {

                throw;
            }
        }
예제 #2
0
파일: Log.cs 프로젝트: hatefi-arman/Modules
        public Log(long id, string code, LogLevel logLevel, User user, string className,
           string methodName, string title, string messages)
        {
            this.id = id;
            this.code = code;
            this.logLevel = logLevel;
            if (user != null)
                this.partyId = user.Id;
            this.className = className;
            this.methodName = methodName;
            this.logDate = DateTime.Now;
            this.logLevelId =(int)logLevel;

            if (!string.IsNullOrEmpty(title) && title.Length > 200)
                this.title = title.Substring(0, 199);
            else
                this.title = title;

            if (!string.IsNullOrEmpty(messages) && messages.Length > 4000)
                this.messages = messages.Substring(0, 3999);
            else
                this.messages = messages;
        }
 private void assignUserGroupsToUser(User user, List<long> groupIds)
 {
     foreach (var groupId in groupIds)
     {
         var group = _userRepository.GetGroupById(groupId);
         user.AssignGroup(group);
     }
 }
예제 #4
0
 public EventLog(long id, string code, LogLevel logLevel, User party, string className,
    string methodName, string title, string messages)
     : base(id, code, logLevel, party, className, methodName, title, messages)
 {
 }
예제 #5
0
        public void TestCustomActionToUserAssignment()
        {
            using (var ctx = new DataContainer())
            {
                foreach (var action in ActionType.GetAllActions())
                {
                    ctx.ActionTypes.Add(action);
                }

                ctx.SaveChanges();
            }

            var user = new User(1, "User", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "fueluser");

            var grantState = false;

            using (var ctx = new DataContainer())
            {
                ctx.Parties.Add(user);
                ctx.SaveChanges();

                user.AssignCustomActions(ActionType.AddCharterOut, grantState);
                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedUser = ctx.Parties.OfType<User>().Single(u => u.Id == 1);

                Assert.IsTrue(insertedUser.CustomActions.Count == 1);

                var addedCustomAction = insertedUser.CustomActions[0];

                Assert.IsTrue(addedCustomAction.PartyId == user.Id &&
                    addedCustomAction.ActionTypeId == ActionType.AddCharterOut.Id &&
                    addedCustomAction.IsGranted == grantState);
            }
        }
예제 #6
0
        public void TestUserInsertion()
        {
            User user = null;

            using (var ctx = new DataContainer())
            {
                user = new User(1, "Party", "f", "l", "e","fueluser");

                ctx.Parties.Add(user);

                ctx.SaveChanges();
            }

            using (var ctx2 = new DataContainer())
            {
                var user2 = ctx2.Parties.OfType<User>().Single(u => u.Id == 1);

                Assert.AreEqual(user.FirstName, user2.FirstName);
            }
        }
예제 #7
0
        public void TestUserGroupsInsertion()
        {
            var user = new User(1, "User", "f", "l", "e", "fueluser");

            using (var ctx = new DataContainer())
            {
                ctx.Parties.Add(user);
                ctx.SaveChanges();

                var group = new Group(2, "Group", "Desc");
                ctx.Parties.Add(group);
                ctx.SaveChanges();

                user.AssignGroup(group);
                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedUser = ctx.Parties.OfType<User>().Single(u => u.Id == 1);

                Assert.IsTrue(
                    insertedUser.Groups.Count == 1 &&
                    insertedUser.Groups.Count(g => g.Id == 2) == 1);

            }
        }
예제 #8
0
        public void TestCustomActionToUserAssignmentLowLevel()
        {
            using (var ctx = new DataContainer())
            {
                foreach (var action in ActionType.GetAllActions())
                {
                    ctx.ActionTypes.Add(action);
                }

                ctx.SaveChanges();
            }

            var user = new User(1, "User", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "fueluser");

            var customAction = new PartyCustomAction(1, ActionType.AddCharterIn.Id, false);

            using (var ctx = new DataContainer())
            {
                ctx.Parties.Add(user);
                ctx.SaveChanges();

                ctx.PartyCustomActions.Add(customAction);
                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedUser = ctx.Parties.OfType<User>().Single(u=>u.Id == 1);

                Assert.IsTrue(insertedUser.CustomActions.Count == 1 &&
                    insertedUser.CustomActions.Count(ca => ca.Id == customAction.Id) == 1);

                var addedCustomAction = insertedUser.CustomActions.Single(ca => ca.Id == customAction.Id);

                Assert.IsNotNull(addedCustomAction);

                Assert.IsTrue(addedCustomAction.ActionTypeId == customAction.ActionTypeId &&
                    addedCustomAction.IsGranted == customAction.IsGranted);
            }
        }
예제 #9
0
 public Log AddExceptionLog(string code, LogLevel logLevel, User user, string className,
                   string methodName, string title, string messages)
 {
     var log = new EventLog(0, code, logLevel, user, className, methodName, title, messages);
     return logManagerService.AddLog(log);
 }