/// <summary> /// Method to get list of all locations (HO/BO/WH/PC). /// </summary> /// <returns>List of Location(s)</returns> public static List <LocationRole> GetAllLocations() { List <LocationRole> lLocations = new List <LocationRole>(); try { using (DataTaskManager dtManager = new DataTaskManager()) { DBParameterList dbParam = new DBParameterList(); using (DataTable dtLocations = dtManager.ExecuteDataTable(GET_ALL_LOCATIONS, dbParam)) { if (dtLocations != null && dtLocations.Rows.Count > 0) { for (int index = 0; index < dtLocations.Rows.Count; index++) { LocationRole tLocation = new LocationRole(); tLocation.LocationId = Convert.ToInt32(dtLocations.Rows[index]["LocationId"]); tLocation.LocationName = Convert.ToString(dtLocations.Rows[index]["LocationName"]); tLocation.LocationType = Convert.ToString(dtLocations.Rows[index]["LocationType"]); lLocations.Add(tLocation); } } else { throw new Exception(Common.GetMessage("2004")); } } } } catch (Exception ex) { throw ex; } return(lLocations); }
/// <summary> /// This method is implementd to search users and return user details as list of users. /// Method will work for returning list of users as well as returning details of particular user i.e. /// associated locations and roles for a single user. /// </summary> /// <param name="xmlDoc">XML file containing values of search parameters.</param> /// <param name="spName">Name of stored procedure to invoke.</param> /// <param name="errorMessage">Error message (if any) returned from stored procedure.</param> /// <returns>List of User(s)</returns> public List <User> UserSearch(string xmlDoc, string spName, ref string errorMessage) { List <User> lUser = new List <User>(); try { using (DataTaskManager dtManager = new DataTaskManager()) { //Declare and initialize the parameter list object. DBParameterList dbParam = new DBParameterList(); //Add the relevant 2 parameters dbParam.Add(new DBParameter(Common.PARAM_DATA, xmlDoc, DbType.String)); dbParam.Add(new DBParameter(Common.PARAM_OUTPUT, string.Empty, DbType.String, ParameterDirection.Output, Common.PARAM_OUTPUT_LENGTH)); using (DataTable dtUserData = dtManager.ExecuteDataTable(spName, dbParam)) { // update database message errorMessage = dbParam[Common.PARAM_OUTPUT].Value.ToString(); if (errorMessage.Length == 0 && dtUserData.Rows.Count > 0) //No dbError { for (int i = 0; i < dtUserData.Rows.Count; i++) { User tUser; int currentUserId = Convert.ToInt32(dtUserData.Rows[i]["UserId"]); //Check duplicate UserId via delegate User tempUser = lUser.Find(delegate(User user) { return(user.UserId == currentUserId); }); if (tempUser == null) //If same UserId does not exist. { tUser = new User(); tUser.UserId = Convert.ToInt32(dtUserData.Rows[i]["UserId"]); tUser.UserName = Convert.ToString(dtUserData.Rows[i]["UserName"]); tUser.FirstName = Convert.ToString(dtUserData.Rows[i]["FirstName"]); tUser.LastName = Convert.ToString(dtUserData.Rows[i]["LastName"]); tUser.Password = Convert.ToString(dtUserData.Rows[i]["Password"]); tUser.Address1 = Convert.ToString(dtUserData.Rows[i]["Address1"]); tUser.Address2 = Convert.ToString(dtUserData.Rows[i]["Address2"]); tUser.Address3 = Convert.ToString(dtUserData.Rows[i]["Address3"]); tUser.Title = Convert.ToInt32(dtUserData.Rows[i]["Title"]); tUser.Dob = Convert.ToDateTime(dtUserData.Rows[i]["dob"]).ToString(Common.DATE_TIME_FORMAT); tUser.Designation = Convert.ToString(dtUserData.Rows[i]["Designation"]); tUser.Email1 = Convert.ToString(dtUserData.Rows[i]["Emailid1"]); tUser.CityId = Convert.ToInt32(dtUserData.Rows[i]["CityId"]); tUser.City = Convert.ToString(dtUserData.Rows[i]["City"]); tUser.PinCode = Convert.ToString(dtUserData.Rows[i]["Pincode"]); tUser.StateId = Convert.ToInt32(dtUserData.Rows[i]["StateId"]); tUser.State = Convert.ToString(dtUserData.Rows[i]["State"]); tUser.CountryId = Convert.ToInt32(dtUserData.Rows[i]["CountryId"]); tUser.Country = Convert.ToString(dtUserData.Rows[i]["Country"]); tUser.PhoneNumber1 = Convert.ToString(dtUserData.Rows[i]["Phone1"]); tUser.Mobile1 = Convert.ToString(dtUserData.Rows[i]["Mobile1"]); tUser.Fax1 = Convert.ToString(dtUserData.Rows[i]["Fax1"]); tUser.Status = Convert.ToInt32(dtUserData.Rows[i]["Status"]); tUser.StatusValue = Convert.ToString(dtUserData.Rows[i]["StatusValue"]); tUser.ModifiedDate = Convert.ToDateTime(dtUserData.Rows[i]["ModifiedDate"]).ToString(Common.DATE_TIME_FORMAT); //Loop for Location-Roles List <LocationRole> lLocRole = new List <LocationRole>(); DataRow[] drLocRole = dtUserData.Select("UserId = " + currentUserId); for (int j = 0; j < drLocRole.Length; j++) { LocationRole tLocRole = new LocationRole(); tLocRole.LocationId = Convert.ToInt32(drLocRole[j]["LocationId"]); tLocRole.LocationName = Convert.ToString(drLocRole[j]["LocationName"]); tLocRole.RoleId = Convert.ToInt32(drLocRole[j]["RoleId"]); tLocRole.RoleName = Convert.ToString(drLocRole[j]["RoleName"]); //Add one by one tLocRole object to lLocRole list lLocRole.Add(tLocRole); } //Loop Location-Roles //Assign list of Location-Role to User object tUser.LocationRoles = lLocRole; //Add one by one tUser object to lUser list lUser.Add(tUser); } } //Loop Roles } } } } catch { throw; } return(lUser); }