Beispiel #1
0
        /// <summary>
        /// Validate User Details while login
        /// </summary>
        /// <param name="request"></param>
        public static void ValidateUserForLogin(LoginRequest request, User account)
        {
            if (account == null)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_DOES_NOT_EXISTS);
                throw new HttpResponseException(response);
            }
            var dbDomain = (from dom in dbContext.Domains
                            join usr in dbContext.Users on dom.Id equals usr.DomainId
                            where usr.Email == request.Email
                            select dom).FirstOrDefault();

            if (dbDomain == null || dbDomain.IsActive == false)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.DOMAIN_IS_INACTIVE);
                throw new HttpResponseException(response);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Validation for the User Role Mapping
        /// </summary>
        public static void ValidateAssignUnAssignRolesToUser(RolesToUserRequest request)
        {
            var dbUser = dbContext.Users.FirstOrDefault(item => item.Id == request.UserId);

            if (dbUser == null)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_DOES_NOT_EXISTS);
                throw new HttpResponseException(response);
            }
            foreach (var item in request.RoleIds)
            {
                if (dbUser.EUSR == null && dbContext.Roles.Where(i => i.Id == item).FirstOrDefault().RoleName.ToUpper() == "ENGINEER")
                {
                    var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.EUSR_DOES_NOT_EXISTS);
                    throw new HttpResponseException(response);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Validation for the User Role Mapping
        /// </summary>
        public static void ValidateDomain(DomainRequest request)
        {
            var dbDomain = dbContext.Domains.FirstOrDefault(item => (item.DomainName == request.DomainName || item.OrgName == request.OrgName) && !item.Deleted);

            if (dbDomain != null)
            {
                if (dbDomain.DomainName == request.DomainName)
                {
                    var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.DOMAIN_EXISTS_ALREADY);
                    throw new HttpResponseException(response);
                }
                else
                {
                    var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.ORG_EXISTS_ALREADY);
                    throw new HttpResponseException(response);
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Validate the request before sending the activation email.
 /// </summary>
 /// <param name="userId"></param>
 public static void ValidateUserforNewPassword(string userId, User user)
 {
     if (user == null)
     {
         // user does not exists.
         var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_DOES_NOT_EXISTS);
         throw new HttpResponseException(response);
     }
     else if (user != null && user.IsActivated == false)
     {
         var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_NOT_ACVTD);
         throw new HttpResponseException(response);
     }
     else if (user != null && user.IsActiveUser == false)
     {
         var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_DEACTIVATED_BY_ADMIN);
         throw new HttpResponseException(response);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Validate the Edit USer details
        /// </summary>
        /// <param name="request"></param>
        public static void ValidateEditUserRequest(string userId, UserEditRequest request, List <string> ChangedProps)
        {
            User user = dbContext.Users.FirstOrDefault(i => i.Id == userId);

            if (user == null)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_DOES_NOT_EXISTS);
                throw new HttpResponseException(response);
            }
            if (string.IsNullOrEmpty(request.FirstName) && ChangedProps.Contains("FirstName"))
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_FIRSTNAME_REQ);
                throw new HttpResponseException(response);
            }
            if (string.IsNullOrEmpty(request.LastName) && ChangedProps.Contains("LastName"))
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_LASTNAME_REQ);
                throw new HttpResponseException(response);
            }
            //check for inprogress assignments.
            if (request.IsActiveUser == false)
            {
                //Abhijeet 06-11-2018
                //Remove PropertyUserMap in Query

                //var assignmentCount = (from pum in user.PropertyUserMaps.Where(i => i.Deleted == false).ToList()
                //                       join pus in user.PropertyUserStatus.Where(i => i.Deleted == false).ToList()
                //                       on pum.Id equals pus.PropertyUserMapsId into temp
                //                       from lj in temp.DefaultIfEmpty()
                //                       where (lj == null || lj.StatusId == null) && pum.Property.Incident.Status == 0
                //                       select new { pum.PropertyId, pum.UserId }).Distinct().Count();

                var assignmentCount = (from pus in user.PropertyUserStatus.Where(i => i.Deleted == false && i.StatusId == null).ToList()

                                       where pus.Property.Incident.Status == 0
                                       select new { pus.PropertyId, pus.UserId }).Distinct().Count();
                if (assignmentCount > 0)
                {
                    var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.UNASSIGN_MPRNs_BEFORE_DEACTIVATE);
                    throw new HttpResponseException(response);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Validation for the User Role Mapping
        /// </summary>
        public static void ValidateForUserRoleMap(UserRoleMapRequest request)
        {
            var dbRole = dbContext.Roles.FirstOrDefault(item => item.Id == request.RoleId);

            if (dbRole == null)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.ROLE_DOES_NOT_EXISTS);
                throw new HttpResponseException(response);
            }
            var dbUser = dbContext.Users.FirstOrDefault(item => item.Id == request.UserId);

            if (dbUser == null)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_DOES_NOT_EXISTS);
                throw new HttpResponseException(response);
            }
            var dbUserRoleMap = dbContext.UserRoleMaps.FirstOrDefault(item => item.RoleId == request.RoleId && item.UserId == request.UserId && !item.Deleted);

            if (dbUserRoleMap != null)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.USER_ROLE_MAP_EXISTS);
                throw new HttpResponseException(response);
            }
        }
Beispiel #7
0
        ///// <summary>
        ///// Validates the request before MPRN Assignments
        ///// </summary>
        //public static void ValidateMPRNAssignment(List<AssignMPRNsRequest> reqList)
        //{
        //    //check for existing mapping..Uncomment once UI passes the RoleId
        //    var invalidUsrRoleMapLst = from req in reqList.Where(i => i.IsUnAssign == false)
        //                               join urm in dbContext.UserRoleMaps.Where(i => i.Deleted == false)
        //                                     on new { req.UserId, req.RoleId } equals new { urm.UserId, urm.RoleId }
        //                               into tempurm
        //                               from urmleftjoin in tempurm.DefaultIfEmpty()
        //                               where urmleftjoin == null || urmleftjoin.Id == null
        //                               select new
        //                               {
        //                                   UserName = dbContext.Users.Where(i => i.Id == req.UserId).Select(i => i.FirstName + " " + i.LastName).FirstOrDefault(),
        //                                   RolName = dbContext.Roles.Where(i => i.Id == req.RoleId).Select(i => i.RoleName).FirstOrDefault()
        //                               };
        //    if (invalidUsrRoleMapLst != null && invalidUsrRoleMapLst.Count() > 0)
        //    {
        //        dynamic result = new ExpandoObject();
        //        result.message = ErrorCodes.USER_ROLE_MAP_DOES_NOT_EXISTS.ToString();
        //        result.UserRoles = invalidUsrRoleMapLst.Select(i => new { UserName = i.UserName, i.RolName }).Distinct();
        //        string output = JsonConvert.SerializeObject(result);
        //        var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output.ToString());
        //        throw new HttpResponseException(response);
        //    }

        //    //check for already assignment and which does not have status..
        //    //If no mapping found then assign can happen.
        //    var existingMapping = from req in reqList.Where(i => i.IsUnAssign == false)
        //                          join pum in dbContext.PropertyUserMap.Where(pum => pum.Deleted == false)
        //                                on new { req.PropertyId, req.UserId, req.RoleId } equals new { pum.PropertyId, pum.UserId, pum.RoleId }
        //                          join pus in dbContext.PropertyUserStatus.Where(pus => pus.Deleted == false)
        //                                 on pum.Id equals pus.PropertyUserMapsId
        //                          into temppus
        //                          from pusleftjoin in temppus.DefaultIfEmpty()
        //                          where pusleftjoin == null || pusleftjoin.StatusId == null
        //                          select new
        //                          {
        //                              pum.PropertyId,
        //                              pum.Property.MPRN,
        //                              pum.User.FirstName,
        //                              pum.User.LastName,
        //                              pum.User.Email,
        //                              pum.Role.RoleName
        //                          };
        //    //find any existing MPRN assignments
        //    if (existingMapping != null && existingMapping.Count() > 0)
        //    {
        //        dynamic result = new ExpandoObject();
        //        result.message = ErrorCodes.USER_MPRN_MAPPING_EXISTS.ToString();
        //        result.UserMPRNs = existingMapping.Select(i => new { i.PropertyId, i.MPRN, UserName = i.FirstName + " " + i.LastName, i.Email, i.RoleName }).Distinct();
        //        string output = JsonConvert.SerializeObject(result);
        //        var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output.ToString());
        //        throw new HttpResponseException(response);
        //    }
        //    // unassignement can happen only when inprogress assignment found.
        //    var inprogressMappings = from req in reqList.Where(i => i.IsUnAssign == true)
        //                             join pum in dbContext.PropertyUserMap.Where(pum => pum.Deleted == false)
        //                                   on new { req.PropertyId, req.UserId, req.RoleId } equals new { pum.PropertyId, pum.UserId, pum.RoleId }
        //                             join pus in dbContext.PropertyUserStatus.Where(pus => pus.Deleted == false)
        //                                    on pum.Id equals pus.PropertyUserMapsId
        //                             into temppus
        //                             from pusleftjoin in temppus.DefaultIfEmpty()
        //                             where pusleftjoin == null || pusleftjoin.StatusId == null
        //                             select new
        //                             {
        //                                 pum.PropertyId,
        //                                 pum.Property.MPRN,
        //                                 pum.User.FirstName,
        //                                 pum.User.LastName,
        //                                 pum.User.Email,
        //                                 pum.Role.RoleName
        //                             };
        //    if (inprogressMappings != null && inprogressMappings.Count() != reqList.Where(i => i.IsUnAssign == true).Count())
        //    {
        //        dynamic result = new ExpandoObject();
        //        result.message = ErrorCodes.NO_INPROGRESS_USER_MPRN_MAPPING.ToString();
        //        string output = JsonConvert.SerializeObject(result);
        //        var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output.ToString());
        //        throw new HttpResponseException(response);
        //    }
        //}

        /// <summary>
        /// Validates the request before MPRN Assignments
        /// </summary>
        public static void ValidateMPRNAssignment(List <AssignMPRNsRequest> reqList)
        {
            //check for existing mapping..Uncomment once UI passes the RoleId
            var invalidUsrRoleMapLst = from req in reqList.Where(i => i.IsUnAssign == false)
                                       join urm in dbContext.UserRoleMaps.Where(i => i.Deleted == false)
                                       on new { req.UserId, req.RoleId } equals new { urm.UserId, urm.RoleId }
            into tempurm
            from urmleftjoin in tempurm.DefaultIfEmpty()
            where urmleftjoin == null || urmleftjoin.Id == null
                select new
            {
                UserName = dbContext.Users.Where(i => i.Id == req.UserId).Select(i => i.FirstName + " " + i.LastName).FirstOrDefault(),
                RolName  = dbContext.Roles.Where(i => i.Id == req.RoleId).Select(i => i.RoleName).FirstOrDefault()
            };

            if (invalidUsrRoleMapLst != null && invalidUsrRoleMapLst.Count() > 0)
            {
                dynamic result = new ExpandoObject();
                result.message   = ErrorCodes.USER_ROLE_MAP_DOES_NOT_EXISTS.ToString();
                result.UserRoles = invalidUsrRoleMapLst.Select(i => new { UserName = i.UserName, i.RolName }).Distinct();
                string output   = JsonConvert.SerializeObject(result);
                var    response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output.ToString());
                throw new HttpResponseException(response);
            }

            //check for already assignment and which does not have status..
            //If no mapping found then assign can happen.
            var existingMapping = from req in reqList.Where(i => i.IsUnAssign == false)
                                  join pus in dbContext.PropertyUserStatus.Where(pus => pus.Deleted == false)
                                  on new { req.PropertyId, req.UserId, req.RoleId } equals new { pus.PropertyId, pus.UserId, pus.RoleId }


            where pus == null || pus.StatusId == null
            select new
            {
                pus.PropertyId,
                pus.Property.MPRN,
                pus.User.FirstName,
                pus.User.LastName,
                pus.User.Email,
                pus.Role.RoleName
            };

            //find any existing MPRN assignments
            if (existingMapping != null && existingMapping.Count() > 0)
            {
                dynamic result = new ExpandoObject();
                result.message   = ErrorCodes.USER_MPRN_MAPPING_EXISTS.ToString();
                result.UserMPRNs = existingMapping.Select(i => new { i.PropertyId, i.MPRN, UserName = i.FirstName + " " + i.LastName, i.Email, i.RoleName }).Distinct();
                string output   = JsonConvert.SerializeObject(result);
                var    response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output.ToString());
                throw new HttpResponseException(response);
            }
            // unassignement can happen only when inprogress assignment found.
            var inprogressMappings = from req in reqList.Where(i => i.IsUnAssign == true)
                                     join pus in dbContext.PropertyUserStatus.Where(pum => pum.Deleted == false)
                                     on new { req.PropertyId, req.UserId, req.RoleId } equals new { pus.PropertyId, pus.UserId, pus.RoleId }

            where pus == null || pus.StatusId == null
            select new
            {
                pus.PropertyId,
                pus.Property.MPRN,
                pus.User.FirstName,
                pus.User.LastName,
                pus.User.Email,
                pus.Role.RoleName
            };

            if (inprogressMappings != null && inprogressMappings.Count() != reqList.Where(i => i.IsUnAssign == true).Count())
            {
                dynamic result = new ExpandoObject();
                result.message = ErrorCodes.NO_INPROGRESS_USER_MPRN_MAPPING.ToString();
                string output   = JsonConvert.SerializeObject(result);
                var    response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output.ToString());
                throw new HttpResponseException(response);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Validates USers Existance
        /// </summary>
        /// <param name="request"></param>
        /// <param name="dbCellManagers"></param>
        /// <param name="dbZoneManagers"></param>
        /// <returns></returns>
        public static void ValidateIncidentManagers(List <PropertyRequest> MPRNs, List <User> dbCellManagers, List <User> dbZoneManagers, List <ResolveUser> resolveUsers)
        {
            List <string> notFoundUsers  = new List <string>();
            List <User>   duplicateUsers = new List <User>();


            string status = string.Empty;

            if (MPRNs != null)
            {
                foreach (var itemMPRN in MPRNs)
                {
                    if (!string.IsNullOrEmpty(itemMPRN.CellManagerName))
                    {
                        var cellManager = dbCellManagers.Where(item => (item.FirstName + " " + item.LastName).ToUpper() == itemMPRN.CellManagerName.ToUpper()).ToList();
                        if (cellManager == null || cellManager.Count == 0)
                        {
                            notFoundUsers.Add(itemMPRN.CellManagerName);
                        }
                        else if (cellManager.Count > 1)
                        {
                            ResolveUser resolvedUser = null;
                            if (resolveUsers != null)
                            {
                                resolvedUser = resolveUsers.FirstOrDefault(i => i.Name == cellManager.First().FirstName + " " + cellManager.First().LastName);
                            }
                            if (resolvedUser == null)
                            {
                                duplicateUsers.AddRange(cellManager);
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(itemMPRN.ZoneManagerName))
                    {
                        var zoneManager = dbZoneManagers.Where(item => (item.FirstName + " " + item.LastName).ToUpper() == itemMPRN.ZoneManagerName.ToUpper()).ToList();
                        if (zoneManager == null || zoneManager.Count == 0)
                        {
                            notFoundUsers.Add(itemMPRN.ZoneManagerName);
                        }
                        else if (zoneManager.Count > 1)
                        {
                            ResolveUser resolvedUser = null;
                            if (resolveUsers != null && resolveUsers.Count > 0)
                            {
                                resolvedUser = resolveUsers.FirstOrDefault(i => i.Name == zoneManager.First().FirstName + " " + zoneManager.First().LastName);
                            }
                            if (resolvedUser == null)
                            {
                                duplicateUsers.AddRange(zoneManager);
                            }
                        }
                    }
                }
            }
            if (notFoundUsers.Count > 0)
            {
                dynamic result = new ExpandoObject();
                result.message = ErrorCodes.USER_DOES_NOT_EXISTS.ToString();
                result.users   = notFoundUsers.Distinct();
                string output = JsonConvert.SerializeObject(result);

                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output);
                throw new HttpResponseException(response);
            }
            if (duplicateUsers.Count > 0)
            {
                dynamic result = new ExpandoObject();
                result.message = ErrorCodes.DUPLICATE_USERS_FOUND.ToString();
                result.users   = duplicateUsers.Select(i => new { Name = i.FirstName + " " + i.LastName, i.Email }).Distinct();
                string output   = JsonConvert.SerializeObject(result);
                var    response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, output.ToString());
                throw new HttpResponseException(response);
            }
        }