private static void DeleteDirectory(string directory) { DirectoryManager dirMgr = new DirectoryManager(); dirMgr.DeleteDirectory(directory); }
/// <summary> /// Adds as new user /// </summary> /// <param name="info"></param> /// <param name="resourceInfo"></param> /// <returns></returns> public string AddUser(UserInfo info, ResourceInfo resourceInfo) { string directory = String.Empty; Guid? resourceId = null; bool hasImage = false; bool hasDirectory = false; try { // Create Directory DirectoryManager dirMgr = new DirectoryManager(); directory = dirMgr.CreateDirectory(); if (!String.IsNullOrWhiteSpace(directory)) hasDirectory = true; hasImage = resourceInfo.Data != null; if (hasImage) { // Add Resource to that directory ResourceManager mgr = new ResourceManager(); resourceId = mgr.AddResource(resourceInfo, directory, EnumPostType.Picture); } using (SqlDataAdapter adapter = new SqlDataAdapter("[user].[AddUserInfo]", AppConfigManager.ConnectionString)) { adapter.SelectCommand.CommandType = CommandType.StoredProcedure; adapter.SelectCommand.Parameters.AddWithValue("@UserName", info.UserName); adapter.SelectCommand.Parameters.AddWithValue("@DisplayName", info.DisplayName); adapter.SelectCommand.Parameters.AddWithValue("@OwnNumber", info.OwnNumber); adapter.SelectCommand.Parameters.AddWithValue("@GenderId", info.GenderId); adapter.SelectCommand.Parameters.AddWithValue("@AgeRangeId", info.AgeRangeId); adapter.SelectCommand.Parameters.AddWithValue("@Status", info.Status); adapter.SelectCommand.Parameters.AddWithValue("@ImageIdf", resourceId); var nodeParam = adapter.SelectCommand.Parameters.Add("@FolderPath", SqlDbType.Udt); nodeParam.Value = SqlHierarchyId.Parse(directory); nodeParam.UdtTypeName = "HierarchyId"; adapter.SelectCommand.Parameters.AddWithValue("@TerritoryId", info.TerritoryId); DataTable dt = new DataTable(); // Gets UserId of Inserted User adapter.Fill(dt); if (dt != null && dt.Rows.Count > 0) { var userIdf = dt.Rows[0][CodeHelper.Idf]; var userFolderPath = dt.Rows[0][CodeHelper.FolderPath]; if (userIdf != null && userFolderPath != null) return JsonWebToken.Encode(new TokenInfo() { Idf = Guid.Parse(userIdf.ToString()), FolderPath = userFolderPath.ToString(), TerritoryId = info.TerritoryId }, CodeHelper.SecretAccessKey, HvHashAlgorithm.RS256); } if (resourceId != null) DeleteFile(resourceId); // Delete directory and file if (hasDirectory) DeleteDirectory(directory); throw new Exception(CodeHelper.UnableToAddUser); } } catch (Exception ex) { string msg = ex.Message; if (resourceId != null) DeleteFile(resourceId); // Delete directory and file if (hasDirectory) DeleteDirectory(directory); throw new Exception(CodeHelper.UnableToAddUser); } }