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; } }
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); } }
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) { }
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); } }
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); } }
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); } }
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); } }
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); }