예제 #1
0
 /// <summary>
 /// To save the Client User association
 /// </summary>
 /// <param name="clientUserMapViewModel"></param>
 /// <returns></returns>
 public bool SaveClientUsers(ClientUserMapViewModel clientUserMapViewModel)
 {
     try
     {
         if (clientUserMapViewModel != null)
         {
             ClientUserMap clientUserMap = new ClientUserMap();
             clientUserMap.ClientCode = clientUserMapViewModel.ClientCode;
             foreach (AllUsersViewModel clientUserViewModel in clientUserMapViewModel.ClientUsers)
             {
                 AllUsers clientUser = new AllUsers();
                 clientUser.Email    = clientUserViewModel.Email;
                 clientUser.RoleName = clientUserViewModel.Role;
                 clientUserMap.ClientUsers.Add(clientUser);
             }
             return(_clientUserRepository.SaveClientUsers(clientUserMap));
         }
         return(false);
     }
     catch (Exception ex)
     {
         _logger.Log(ex, LogLevel.Error, ex.Message);
         return(false);
     }
 }
예제 #2
0
        /// <summary>
        /// User to save ClientUsers association
        /// </summary>
        /// <param name="clientUserMap"></param>
        /// <returns></returns>
        public bool SaveClientUsers(ClientUserMap clientUserMap)
        {
            try
            {
                UserContext userContext = UserHelper.getUserContext();

                List <string> selectedUsers = clientUserMap.ClientUsers.Select(c => c.Email).ToList();

                //All the Existing UserIds of a client
                List <UserClientMap> existingClientUserMap = _m3pactContext.UserClientMap.Include(DomainConstants.Client)
                                                             .Where(c => c.Client.ClientCode == clientUserMap.ClientCode &&
                                                                    c.RecordStatus == DomainConstants.RecordStatusActive)?.ToList();

                List <int> existingClientUserIds = existingClientUserMap.Select(c => c.UserId).ToList();

                //All the UserIds assigned
                List <int> userIds = _m3pactContext.UserLogin.Where(c => c.Email.Any(cu => selectedUsers.Contains(c.Email))).Select(d => d.Id).ToList();

                //Newly Added UserIds
                IEnumerable <int> newlyAddedUserIds = userIds.Except(existingClientUserIds);
                IEnumerable <int> notChangedUserIds = userIds.Intersect(existingClientUserIds);

                if (notChangedUserIds != null)
                {
                    existingClientUserMap.Where(ec => !notChangedUserIds.Contains(ec.UserId)).ToList()?
                    .ForEach(c =>
                    {
                        c.RecordStatus = DomainConstants.RecordStatusInactive;
                        c.ModifiedDate = DateTime.Now;
                        c.ModifiedBy   = userContext.UserId;
                    });
                    _m3pactContext.UserClientMap.UpdateRange(existingClientUserMap);
                }
                int clientId = (int)_m3pactContext.Client.Where(c => c.ClientCode == clientUserMap.ClientCode).First()?.ClientId;
                foreach (int userId in newlyAddedUserIds)
                {
                    _m3pactContext.UserClientMap.Add(new UserClientMap()
                    {
                        ClientId     = clientId,
                        UserId       = userId,
                        RecordStatus = DomainConstants.RecordStatusActive,
                        CreatedBy    = userContext.UserId,
                        CreatedDate  = DateTime.Now,
                        ModifiedBy   = userContext.UserId,
                        ModifiedDate = DateTime.Now,
                    });
                }
                return(_m3pactContext.SaveChanges() > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        /// <summary>
        /// To Get all the users associated with the client
        /// </summary>
        /// <param name="clientCode"></param>
        /// <returns></returns>
        public ClientUserMapViewModel GetUsersForClient(string clientCode)
        {
            ClientUserMapViewModel clientUserMapViewModel = new ClientUserMapViewModel();

            try
            {
                ClientUserMap clientUserData = _clientUserRepository.GetUsersForClient(clientCode);
                clientUserMapViewModel.ClientCode = clientCode;
                foreach (AllUsers user in clientUserData?.ClientUsers)
                {
                    clientUserMapViewModel.ClientUsers.Add(BusinessMapper.AllUsersBusinessToAllUsesrViewModel(user));
                }
            }
            catch (Exception ex)
            {
                _logger.Log(ex, LogLevel.Error, ex.Message);
                clientUserMapViewModel.Success = false;
                clientUserMapViewModel.ErrorMessages.Add(BusinessConstants.ERROR_GET_DETAILS);
            }
            return(clientUserMapViewModel);
        }
예제 #4
0
        public void TestCreateMapForClassWithFieldDefinedByMapAndBuilder()
        {
            //--Act
            var clientUserMap = new ClientUserMap();

            DisplayTableMapColumns(clientUserMap);

            //--Assert
            Assert.AreEqual("Client_User", clientUserMap.TableName);

            var clientId = clientUserMap[x => x.ClientId];

            Assert.AreEqual(nameof(ClientUser.ClientId), clientId.ColumnName);
            Assert.AreEqual(ColumnBehavior.Key, clientId.Behavior);
            Assert.AreEqual(SqlOperation.Update, clientId.IgnoreOperations);

            var userId = clientUserMap[x => x.UserId];

            Assert.AreEqual(nameof(ClientUser.UserId), userId.ColumnName);
            Assert.AreEqual(ColumnBehavior.Key, userId.Behavior);
            Assert.AreEqual(SqlOperation.Update, userId.IgnoreOperations);

            var isActive = clientUserMap[x => x.IsActive];

            Assert.AreEqual(nameof(ClientUser.IsActive), isActive.ColumnName);
            Assert.AreEqual(ColumnBehavior.Basic, isActive.Behavior);
            Assert.AreEqual(SqlOperation.None, isActive.IgnoreOperations);

            foreach (var type in clientUserMap.TypeColumns)
            {
                Console.WriteLine(type.Key.Name);
                foreach (var(property, columnMap) in type.Value.AsTuples())
                {
                    Console.WriteLine($"-{property} => {columnMap.Behavior}");
                }
            }

            Assert.AreSame(clientUserMap.TypeColumns[typeof(IClientRecord)].Values.First(), clientUserMap.TypeColumns[typeof(ClientUser)].Values.First());
        }
 public void AddToClientUserMaps(ClientUserMap clientUserMap)
 {
     base.AddObject("ClientUserMaps", clientUserMap);
 }
 public static ClientUserMap CreateClientUserMap(int ID, byte[] rowVersion, int clientUserMap_User, int clientUserMap_Client)
 {
     ClientUserMap clientUserMap = new ClientUserMap();
     clientUserMap.Id = ID;
     clientUserMap.RowVersion = rowVersion;
     clientUserMap.ClientUserMap_User = clientUserMap_User;
     clientUserMap.ClientUserMap_Client = clientUserMap_Client;
     return clientUserMap;
 }