diff --git a/Controllers/DbClientController.cs b/Controllers/DbClientController.cs index 4d0213ee9..ea3ffad92 100644 --- a/Controllers/DbClientController.cs +++ b/Controllers/DbClientController.cs @@ -11,6 +11,8 @@ using ExpressBase.Objects.Objects.DVRelated; using ExpressBase.Common; using ExpressBase.Common.Structures; +using System.Linq; +using System.Text.RegularExpressions; namespace ExpressBase.Web.Controllers { @@ -26,7 +28,7 @@ public IActionResult DbClient(string clientSolnid) { try { - if (ViewBag.wc != RoutingConstants.DC) + if (ViewBag.wc == RoutingConstants.UC || ViewBag.wc == RoutingConstants.TC) return Redirect("/StatusCode/401"); //GetDbTablesResponse res = null; //if (ViewBag.cid == "admin" && this.LoggedInUser.Roles.Contains(SystemRoles.SolutionOwner.ToString()) || this.LoggedInUser.Roles.Contains(SystemRoles.SolutionAdmin.ToString())) @@ -58,9 +60,6 @@ public IActionResult DbClient(string clientSolnid) [HttpPost] public IActionResult DbClientt() { - if (ViewBag.wc != RoutingConstants.DC) - return Redirect("/StatusCode/401"); - GetDbTablesResponse res = null; if (ViewBag.cid == "admin") if (this.LoggedInUser.Roles.Contains(SystemRoles.SolutionOwner.ToString()) || this.LoggedInUser.Roles.Contains(SystemRoles.SolutionAdmin.ToString())) @@ -74,21 +73,23 @@ public IActionResult DbClientt() public IActionResult SearchSolution(string clientSolnid) { - if (ViewBag.wc != RoutingConstants.DC) + if (ViewBag.wc == RoutingConstants.UC || ViewBag.wc == RoutingConstants.TC) return Redirect("/StatusCode/401"); var user = this.LoggedInUser; return ViewComponent("DBClient", new { clientSolnid = clientSolnid, _user = user }); } public List ExecuteQuery(string Query, string solution, bool Isadmin) - { + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } solutionid = solution; IsAdmin = Isadmin; - List responses = new List(); - - if (ViewBag.wc != RoutingConstants.DC) - return responses; + int createdByUserId = this.LoggedInUser.UserId; + List responses = new List(); string[] QueryList = Query.Split(";"); try { @@ -96,13 +97,6 @@ public List ExecuteQuery(string Query, string solution, b { if (SplitQuery != string.Empty) { - if (Query.IndexOf("delete ", StringComparison.OrdinalIgnoreCase) >= 0 || - Query.IndexOf("drop ", StringComparison.OrdinalIgnoreCase) >= 0 || - Query.IndexOf("truncate ", StringComparison.OrdinalIgnoreCase) >= 0) - { - break; - } - if (Query.IndexOf("insert into ", StringComparison.OrdinalIgnoreCase) >= 0) { DbClientQueryResponse ress = new DbClientQueryResponse(); @@ -111,19 +105,37 @@ public List ExecuteQuery(string Query, string solution, b } else if (Query.IndexOf("select ", StringComparison.OrdinalIgnoreCase) >= 0) { - if (Query.IndexOf("eb_", StringComparison.OrdinalIgnoreCase) < 0 || IsAdmin) + // if (Query.IndexOf("eb_", StringComparison.OrdinalIgnoreCase) < 0 || IsAdmin) { DbClientQueryResponse ress = new DbClientQueryResponse(); ress = SelectQuery(SplitQuery); responses.Add(ress); } } + else if (Query.IndexOf("delete ", StringComparison.OrdinalIgnoreCase) >= 0) + { + DbClientQueryResponse ress = new DbClientQueryResponse(); + ress = DeleteQuery(SplitQuery); + responses.Add(ress); + } + else if (Query.IndexOf("drop ", StringComparison.OrdinalIgnoreCase) >= 0) + { + DbClientQueryResponse ress = new DbClientQueryResponse(); + ress = DropQuery(SplitQuery); + responses.Add(ress); + } else if (Query.IndexOf("alter table ", StringComparison.OrdinalIgnoreCase) >= 0) { DbClientQueryResponse ress = new DbClientQueryResponse(); ress = AlterQuery(SplitQuery); responses.Add(ress); } + else if (Query.IndexOf("truncate ", StringComparison.OrdinalIgnoreCase) >= 0) + { + DbClientQueryResponse ress = new DbClientQueryResponse(); + ress = TruncateQuery(SplitQuery); + responses.Add(ress); + } else if (Query.IndexOf("update ", StringComparison.OrdinalIgnoreCase) >= 0) { DbClientQueryResponse ress = new DbClientQueryResponse(); @@ -136,6 +148,7 @@ public List ExecuteQuery(string Query, string solution, b ress = CreateQuery(SplitQuery); responses.Add(ress); } + else { } } } } @@ -146,13 +159,39 @@ public List ExecuteQuery(string Query, string solution, b return responses; } + + + + + + + public DbClientQueryResponse SelectQuery(string Query) { - DbClientQueryResponse ress = new DbClientQueryResponse(); if (ViewBag.wc != RoutingConstants.DC) - return ress; - //bool containsSearchResult = Query.Contains("select"); - ress = this.ServiceClient.Post(new DbClientSelectRequest { Query = Query, ClientSolnid = solutionid, IsAdminOwn = IsAdmin }); + { + throw new UnauthorizedAccessException("Unauthorized access"); + } + + string queryLower = Query.ToLower(); + + // Block SELECT * on sensitive tables + if (queryLower.Contains("select *") && + (queryLower.Contains("from eb_downloads") || queryLower.Contains("from eb_files_bytea"))) + { + throw new InvalidOperationException("SELECT * is not allowed on tables with large BYTEA data. Please specify non-BYTEA columns explicitly."); + } + + // Block SELECT of BYTEA columns directly from sensitive tables + if ((queryLower.Contains("from eb_downloads") || queryLower.Contains("from eb_files_bytea")) && + queryLower.Contains("bytea")) + { + throw new InvalidOperationException("Selecting BYTEA columns directly is not allowed on these tables."); + } + + DbClientQueryResponse ress = this.ServiceClient.Post( + new DbClientSelectRequest { Query = Query, ClientSolnid = solutionid, IsAdminOwn = IsAdmin }); + if (ress.Dataset != null) { ress.RowCollection = new List(); @@ -165,55 +204,397 @@ public DbClientQueryResponse SelectQuery(string Query) } return ress; } + [HttpPost] + public ActionResult GetDbClientLogs(string tableName, bool Isadmin) + { + if (ViewBag.wc != RoutingConstants.DC) + { + return Unauthorized(); + } + + string solution = this.solutionid ?? ViewBag.Cid; + + DbClientLogsRequest request = new DbClientLogsRequest + { + TableName = tableName, + SolutionId = solution, + IsAdminOwn = Isadmin + }; + + try + { + List logs = this.ServiceClient.Post>(request); + + return Json(new + { + success = true, + message = "Logs fetched successfully", + data = logs + }); + } + catch (Exception ex) + { + return Json(new + { + success = false, + message = "Failed to fetch logs", + error = ex.Message + }); + } + } + + + + + + public ActionResult CreateIndex(string tableName, string indexName, string indexColumns, bool Isadmin) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + return Unauthorized(); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; + // Create the request object + DbClientIndexRequest request = new DbClientIndexRequest + { + TableName = tableName, + IndexName = indexName, + IndexColumns = indexColumns, + ClientSolnid = solution, + CreatedByUserId = createdByUserId, + IsAdminOwn = Isadmin + }; + + // Execute the request + DbClientIndexResponse response = this.ServiceClient.Post(request); + + // Return the appropriate ActionResult + if (response.Result == 0) // Assuming 0 indicates success, adjust as needed + { + return Json(new { success = true, message = "Index created successfully." }); + } + else + { + return Json(new { success = false, message = "Failed to create index.", error = response.Message }); + } + } + + + [HttpPost] + public ActionResult EditIndexName(string currentIndexName, string newIndexName, string tableName, bool Isadmin) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + return Unauthorized(); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; + + // Create the request object + DbClientEditIndexRequest request = new DbClientEditIndexRequest + { + CurrentIndexName = currentIndexName, + NewIndexName = newIndexName, + TableName = tableName, + ClientSolnid = solution, + CreatedByUserId = createdByUserId, + IsAdminOwn = Isadmin + }; + + // Execute the request + DbClientEditIndexResponse response = this.ServiceClient.Post(request); + + // Return the appropriate ActionResult + if (response.Result == 0) // Assuming 0 indicates success, adjust as needed + { + return Json(new { success = true, message = "Index name updated successfully." }); + } + else + { + return Json(new { success = false, message = "Failed to update index name.", error = response.Message }); + } + } + + + + [HttpPost] + public ActionResult CreateConstraint(string tableName, string columnName, string constraintType, string constraintName, bool Isadmin) + { + // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + return Unauthorized(); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; + // Create the request object + DbClientConstraintRequest request = new DbClientConstraintRequest + { + TableName = tableName, + ColumnName = columnName, + ConstraintType = constraintType, + ConstraintName = constraintName, + ClientSolnid = solution, + CreatedByUserId = createdByUserId, + IsAdminOwn = Isadmin + }; + + // Execute the request + DbClientConstraintResponse response = this.ServiceClient.Post(request); + + // Ensure the message consistency + if (response.Message == "Constraint created successfully") + { + return Json(new { success = true, message = response.Message }); + } + else + { + string errorMessage = response.Message.StartsWith("Error: ") ? response.Message : "Failed to create constraint: " + response.Message; + return Json(new { success = false, message = errorMessage }); + } + } + [HttpPost] + public ActionResult GetFunctionHistory(string functionName) + { + if (ViewBag.wc != RoutingConstants.DC) + return Unauthorized(); + + string solution = this.solutionid ?? ViewBag.Cid; + + // Build request DTO + DbClientFunctionHistoryRequest request = new DbClientFunctionHistoryRequest + { + FunctionName = functionName, + SolutionId = solution, + IsAdminOwn = true // or use ViewBag/LoggedInUser if needed + }; + + // Call service + var history = this.ServiceClient.Post>(request); + + return Json(new { success = true, data = history }); + } + + [HttpPost] + public ActionResult LogEditedFunction(string functionName, string functionCode, bool Isadmin) + { + // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + return Unauthorized(); + } + + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; + + // Build request + DbClientLogEditedFunctionRequest request = new DbClientLogEditedFunctionRequest + { + FunctionName = functionName, + FunctionCode = functionCode, + ClientSolnid = solution, + CreatedByUserId = createdByUserId, + IsAdminOwn = Isadmin + }; + + // Call service + DbClientLogEditedFunctionResponse response = this.ServiceClient.Post(request); + + if (response.Message == "Function edit logged successfully") + { + return Json(new { success = true, message = response.Message }); + } + else + { + string errorMessage = response.Message.StartsWith("Error: ") + ? response.Message + : "Failed to log function edit: " + response.Message; + + return Json(new { success = false, message = errorMessage }); + } + } + + - private DbClientQueryResponse InsertQuery(string Query) + [HttpPost] + public ActionResult CreateFunction(string functionName, string functionCode, bool Isadmin) { + // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + return Unauthorized(); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; + // Create the request object + DbClientCreateFunctionRequest request = new DbClientCreateFunctionRequest + { + FunctionName = functionName, + FunctionCode = functionCode, + ClientSolnid = solution, + IsAdminOwn = Isadmin, + CreatedByUserId = createdByUserId + + }; + // Execute the request + DbClientCreateFunctionResponse response = this.ServiceClient.Post(request); + // Ensure the message consistency + if (response.Message == "Function created successfully") + { + return Json(new + { + success = true, + message = response.Message, + FunctionName = response.FunctionName + }); + } + else + { + string errorMessage = response.Message.StartsWith("Error: ") + ? response.Message + : "Failed to create function: " + response.Message; + + return Json(new + { + success = false, + message = errorMessage + }); + } + } + + + [HttpPost] + public IActionResult GetFunctionByName(string functionName, string solution, bool isAdmin) + { + try + { + // Store solution and admin flag + this.solutionid = solution; + this.IsAdmin = isAdmin; + + + // Call service to get functions + var response = this.ServiceClient.Get(new GetDbTablesRequest + { + IsAdminOwn = isAdmin, + ClientSolnid = solution, + + }); + + // Search for matching function + var matchedFunction = response.Tables.FunctionCollection + .FirstOrDefault(f => f.FunctionName == functionName); + + if (matchedFunction != null) + { + return Json(new + { + success = true, + name = matchedFunction.FunctionName, + definition = matchedFunction.FunctionQuery + }); + } + + return Json(new { success = false, message = "Function not found" }); + } + catch (Exception ex) + { + return Json(new { success = false, message = ex.Message }); + } + } + + + + public DbClientQueryResponse InsertQuery(string Query) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; DbClientQueryResponse ress = new DbClientQueryResponse(); - ress = this.ServiceClient.Post(new DbClientInsertRequest { Query = Query, ClientSolnid = solutionid, IsAdminOwn = IsAdmin }); + ress = this.ServiceClient.Post(new DbClientInsertRequest { Query = Query, ClientSolnid = solution, IsAdminOwn = IsAdmin,CreatedByUserId = createdByUserId }); return ress; } - private DbClientQueryResponse DropQuery(string Query) - { + public DbClientQueryResponse DropQuery(string Query) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; DbClientQueryResponse ress = new DbClientQueryResponse(); return ress; } - private DbClientQueryResponse DeleteQuery(string Query) - { + public DbClientQueryResponse DeleteQuery(string Query) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; DbClientQueryResponse ress = new DbClientQueryResponse(); - ress = this.ServiceClient.Post(new DbClientDeleteRequest { Query = Query, ClientSolnid = solutionid, IsAdminOwn = IsAdmin }); + ress = this.ServiceClient.Post(new DbClientDeleteRequest { Query = Query, ClientSolnid = solution, IsAdminOwn = IsAdmin, CreatedByUserId = createdByUserId }); return ress; } - private DbClientQueryResponse AlterQuery(string Query) - { + public DbClientQueryResponse AlterQuery(string Query) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; DbClientQueryResponse ress = new DbClientQueryResponse(); - ress = this.ServiceClient.Post(new DbClientAlterRequest { Query = Query, ClientSolnid = solutionid, IsAdminOwn = IsAdmin }); + ress = this.ServiceClient.Post(new DbClientAlterRequest { Query = Query, ClientSolnid = solution, IsAdminOwn = IsAdmin, CreatedByUserId = createdByUserId }); return ress; } private DbClientQueryResponse CreateQuery(string Query) - { + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; DbClientQueryResponse ress = new DbClientQueryResponse(); - ress = this.ServiceClient.Post(new DbClientCreateRequest { Query = Query, ClientSolnid = solutionid, IsAdminOwn = IsAdmin }); + ress = this.ServiceClient.Post(new DbClientCreateRequest { Query = Query, ClientSolnid = solution, IsAdminOwn = IsAdmin, CreatedByUserId = createdByUserId }); return ress; } - private DbClientQueryResponse TruncateQuery(string Query) - { + public DbClientQueryResponse TruncateQuery(string Query) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } DbClientQueryResponse ress = new DbClientQueryResponse(); return ress; } - private DbClientQueryResponse UpdateQuery(string Query) - { + public DbClientQueryResponse UpdateQuery(string Query) + { // Check if the user is a developer + if (ViewBag.wc != RoutingConstants.DC) + { + throw new UnauthorizedAccessException("Unauthorized access"); + } + int createdByUserId = this.LoggedInUser.UserId; + string solution = this.solutionid ?? ViewBag.Cid; DbClientQueryResponse ress = new DbClientQueryResponse(); ress = this.ServiceClient.Post(new DbClientUpdateRequest { Query = Query, ClientSolnid = solutionid, IsAdminOwn = IsAdmin }); return ress; } - private DVColumnCollection ConvertColumns(ColumnColletion __columns) + + public DVColumnCollection ConvertColumns(ColumnColletion __columns) { DVColumnCollection Columns = new DVColumnCollection(); foreach (EbDataColumn column in __columns) @@ -227,6 +608,10 @@ private DVColumnCollection ConvertColumns(ColumnColletion __columns) _col = new DVBooleanColumn { Data = column.ColumnIndex, Name = column.ColumnName, sTitle = column.ColumnName, Type = column.Type, bVisible = true, sWidth = "100px" }; else if (column.Type == EbDbTypes.DateTime || column.Type == EbDbTypes.Date || column.Type == EbDbTypes.Time) _col = new DVDateTimeColumn { Data = column.ColumnIndex, Name = column.ColumnName, sTitle = column.ColumnName, sType = "date-uk", Type = column.Type, bVisible = true, sWidth = "100px" }; + else + { + continue; + } _col.EbSid = column.Type.ToString() + column.ColumnIndex; _col.RenderType = _col.Type; Columns.Add(_col); @@ -235,3 +620,4 @@ private DVColumnCollection ConvertColumns(ColumnColletion __columns) } } } + diff --git a/Controllers/SupportTicketController.cs b/Controllers/SupportTicketController.cs index fb3633d46..3620182b1 100644 --- a/Controllers/SupportTicketController.cs +++ b/Controllers/SupportTicketController.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Http; using System.Collections.Specialized; using System.IO; +using ExpressBase.Common.LocationNSolution; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -48,21 +49,42 @@ public IActionResult BugTickets() FetchSupportResponse fsr = this.ServiceClient.Post(new FetchSupportRequest()); // Debugging: Log the count of tickets fetched - if (fsr.supporttkt != null) + Console.WriteLine($"Active Tickets Count: {fsr.ActiveTicket?.Count ?? 0}"); + Console.WriteLine($"Closed Tickets Count: {fsr.ClosedTicket?.Count ?? 0}"); + + // Return both Active and Closed tickets as JSON + var result = new + { + ActiveTickets = fsr.ActiveTicket ?? new List(), + ClosedTickets = fsr.ClosedTicket ?? new List() + }; + + return Json(result); + } + [HttpGet] + public IActionResult GetTicketById(string ticketId) + { + if (string.IsNullOrWhiteSpace(ticketId)) { - Console.WriteLine($"Fetched Tickets Count: {fsr.supporttkt.Count}"); + return BadRequest("Ticket ID is required."); + } + + // Call service to get the ticket details + var request = new GetTicketByIdRequest { TicketId = ticketId }; + GetTicketByIdResponse response = this.ServiceClient.Get(request); + + if (response?.Ticket != null) + { + return Json(response.Ticket); } else { - Console.WriteLine("No tickets found in the response."); + return NotFound("Ticket not found."); } - - // Directly return all tickets as JSON response - // No filtering is done here - return Json(fsr.supporttkt ?? new List()); } + public IActionResult EditTicket(string tktno) { if (ViewBag.wc.Equals("tc")) @@ -184,7 +206,7 @@ public void SaveBugDetails(string title, string stats, string descp, string prio } [HttpPost] - public SubmitTicketResponse SubmitTicketDetails(string title, string stats, string descp, string priority, string solid, string type, object fileCollection) + public SubmitTicketResponse SubmitTicketDetails(string title, string stats, string descp, string priority, string solid, string type) { var stresponse = new SubmitTicketResponse(); string usrtyp = null; @@ -214,43 +236,41 @@ public SubmitTicketResponse SubmitTicketDetails(string title, string stats, stri // File upload part if (httpreq.Files.Count > 0) { - byte[] fileData = null; + Console.WriteLine($"Total files received: {httpreq.Files.Count}"); - for (int i = 0; i < httpreq.Files.Count; i++) + foreach (var file in httpreq.Files) { - var file = httpreq.Files[i]; - if ((file.ContentType == "image/jpeg") || (file.ContentType == "image/jpg") || (file.ContentType == "image/png") || (file.ContentType == "application/pdf")) + Console.WriteLine($"Received File: {file.FileName} - {file.ContentType} - {file.Length} bytes"); + + if (file != null && file.Length > 0) { - if (file.Length < 2097152) // File size limit: 2MB + FileUploadCls flup = new FileUploadCls(); + using (var memoryStream = new MemoryStream()) { - FileUploadCls flup = new FileUploadCls(); - using (var memoryStream = new MemoryStream()) - { - file.CopyTo(memoryStream); - memoryStream.Seek(0, SeekOrigin.Begin); - fileData = new byte[memoryStream.Length]; - memoryStream.ReadAsync(fileData, 0, fileData.Length); - flup.Filecollection = fileData; - } - flup.FileName = file.FileName; - flup.ContentType = file.ContentType; - strequest.Fileuploadlst.Add(flup); + file.CopyTo(memoryStream); + flup.Filecollection = memoryStream.ToArray(); } + flup.FileName = file.FileName; + flup.ContentType = file.ContentType; + strequest.Fileuploadlst.Add(flup); } } } - // Populate the SubmitTicketRequest object with form data strequest.title = httpreq["title"].ToString(); strequest.description = httpreq["description"].ToString(); strequest.priority = httpreq["priority"].ToString(); - strequest.solutionid = solid; - strequest.type_b_f = httpreq["type"].ToString(); - strequest.status = httpreq["stats"].ToString(); + strequest.solutionid = solid; // Use the 'solid' parameter + strequest.type_b_f = httpreq["type_f_b"].ToString(); // Use type_f_b from js + strequest.status = httpreq["status"].ToString(); strequest.usertype = usrtyp; strequest.fullname = this.LoggedInUser.FullName; strequest.email = this.LoggedInUser.Email; + strequest.onBehalfOf = httpreq.ContainsKey("onBehalfOf") && int.TryParse(httpreq["onBehalfOf"], out int onBehalfValue) + ? onBehalfValue + : 0; // Default to 0 if no valid ID is provided + // Post the ticket request to the service stresponse = this.ServiceClient.Post(strequest); @@ -281,58 +301,110 @@ public SubmitTicketResponse SubmitTicketDetails(string title, string stats, stri return stresponse; } - public void UpdateTicket(string filedelet, string solu_id, string tktid, string updtkt) + [HttpGet] + public Dictionary GetUsers(string cid) { + + Eb_Solution s_obj = GetSolutionObject(cid); // Retrieve solution object + if (s_obj != null && s_obj.Users != null) + { + // var usersList = s_obj.Users.Select(user => new + // { + // Id = user.UserId, // Adjust according to actual user properties + // Name = user.UserName + // }).ToList(); + + // return Ok(usersList); + return s_obj.Users; + } + return null; + + + } - UpdateTicketRequest Uptkt = new UpdateTicketRequest(); - var httpreq = this.HttpContext.Request.Form; - Dictionary chngtkt = JsonConvert.DeserializeObject>(updtkt); - if (httpreq.Files.Count > 0) + + [HttpPost] + public IActionResult UpdateTicket() + { + try { - byte[] fileData = null; + var httpRequest = HttpContext.Request.Form; + UpdateTicketRequest uptkt = new UpdateTicketRequest + { + Fileuploadlst = new List() + }; - for (int i = 0; i < httpreq.Files.Count; i++) + // Check required fields + if (string.IsNullOrEmpty(httpRequest["updtkt"])) { + return Json(new { errorMessage = "Error: 'updtkt' field is missing in the request." }); + } + if (string.IsNullOrEmpty(httpRequest["ticketId"])) + { + return Json(new { errorMessage = "Error: 'ticketId' field is missing in the request." }); + } + if (string.IsNullOrEmpty(httpRequest["solu_id"])) + { + return Json(new { errorMessage = "Error: 'solu_id' field is missing in the request." }); + } - var file = httpreq.Files[i]; - if ((file.ContentType == "image/jpeg") || (file.ContentType == "image/jpg") || (file.ContentType == "image/png") || (file.ContentType == "application/pdf")) + // Deserialize JSON input + Dictionary changedTkt = JsonConvert.DeserializeObject>(httpRequest["updtkt"]); + uptkt.chngedtkt = changedTkt; + uptkt.ticketid = httpRequest["ticketId"]; + uptkt.solution_id = httpRequest["solu_id"]; + uptkt.usrname = this.LoggedInUser?.FullName ?? "Unknown User"; + + // Process uploaded files + foreach (var file in httpRequest.Files) + { + if (file.Length < 2097152) // Keep size restriction (2MB) { - if (file.Length < 2097152) + using (var memoryStream = new MemoryStream()) { - FileUploadCls flup = new FileUploadCls(); - using (var memoryStream = new MemoryStream()) + file.CopyTo(memoryStream); + byte[] fileData = memoryStream.ToArray(); + + uptkt.Fileuploadlst.Add(new FileUploadCls { - file.CopyTo(memoryStream); - memoryStream.Seek(0, SeekOrigin.Begin); - fileData = new byte[memoryStream.Length]; - memoryStream.ReadAsync(fileData, 0, fileData.Length); - flup.Filecollection = fileData; - } - flup.FileName = file.FileName; - flup.ContentType = file.ContentType; - Uptkt.Fileuploadlst.Add(flup); + Filecollection = fileData, + FileName = file.FileName, + ContentType = file.ContentType + }); } } } - } - Uptkt.Filedel = JsonConvert.DeserializeObject(filedelet); - Uptkt.usrname = this.LoggedInUser.FullName; - Uptkt.chngedtkt = chngtkt; - Uptkt.ticketid = tktid; - if (this.LoggedInUser.wc.Equals("tc")) - { - Uptkt.solution_id = solu_id; + + // Debugging logs + Console.WriteLine("Ticket update request received:"); + Console.WriteLine($"Ticket ID: {uptkt.ticketid}"); + Console.WriteLine($"Solution ID: {uptkt.solution_id}"); + Console.WriteLine($"Username: {uptkt.usrname}"); + Console.WriteLine($"Changes: {JsonConvert.SerializeObject(uptkt.chngedtkt)}"); + Console.WriteLine($"Attached Files: {uptkt.Fileuploadlst.Count}"); + + // Call service + UpdateTicketResponse upr = this.ServiceClient.Post(uptkt); + + if (upr.status) + { + return Json(new { successMessage = "Ticket updated successfully" }); + } + else + { + return Json(new { errorMessage = "Failed to update ticket" }); + } } - else + catch (Exception ex) { - Uptkt.solution_id = ViewBag.cid; + return Json(new { errorMessage = $"Error: {ex.Message}" }); } - UpdateTicketResponse upr = this.ServiceClient.Post(Uptkt); - } + + public void UpdateTicketAdmin(string updtkt, string tktid, string solid) { @@ -362,18 +434,40 @@ public void ChangeStatus(string tktno, string reason) } - public void Comment(string tktno, string cmnt) + [HttpPost] + public IActionResult Comment(string TicketNo, string Comments, string UserName, string Solution_id,string currentUserid) { CommentResponse Cr = this.ServiceClient.Post(new CommentRequest { - TicketNo = tktno, - Comments = cmnt, - UserName = this.LoggedInUser.FullName, - Solution_id = ViewBag.cid + TicketNo = TicketNo, + Comments = Comments, + UserName = UserName, + Solution_id = Solution_id, + currentUserid=currentUserid + + }); + return Json(Cr); + } + + [HttpGet] + public IActionResult CommentsByTicket(string tktno) + { + var response = this.ServiceClient.Post( + new CommentListRequest + { + TicketNo = tktno + }); + + return Json(response); } + + + + } } + diff --git a/Views/DbClient/DbClient.cshtml b/Views/DbClient/DbClient.cshtml index 69c1b6fb6..e9b91ad7e 100644 --- a/Views/DbClient/DbClient.cshtml +++ b/Views/DbClient/DbClient.cshtml @@ -8,15 +8,15 @@ @await Component.InvokeAsync("PageHeaderCommon"); @**@ - + diff --git a/Views/Shared/Components/DBClient/DbClientComponent.cshtml b/Views/Shared/Components/DBClient/DbClientComponent.cshtml index 020bd360a..4c014aade 100644 --- a/Views/Shared/Components/DBClient/DbClientComponent.cshtml +++ b/Views/Shared/Components/DBClient/DbClientComponent.cshtml @@ -1,10 +1,22 @@ @using ExpressBase.Objects.ServiceStack_Artifacts; @using Newtonsoft.Json; + + +@using System.Collections.Generic; +@using System.Linq; + + @{ if (ViewBag.Message == null) { @@ -32,111 +44,569 @@
- @ViewBag.DB_Name + @ViewBag.DB_Name + +
-
- Tables ( @ViewBag.TableCount ) - @{ foreach (KeyValuePair Table_kvp in ViewBag.Tables.TableCollection) + Schemas + @{ + // Initialize a dictionary to group tables by schema + var schemaGroups = new Dictionary>>(); + var tableCollection = ViewBag.Tables.TableCollection as Dictionary; + + // Group tables by schema + foreach (var table_kvp in tableCollection) { -
- @* - *@ - @{ - EbDbExplorerTable table = Table_kvp.Value; - string schema = table.Schema; - List Indexes = table.Index; - List Columns = table.Columns; - - @Table_kvp.Key - -
- Schema ( @schema ) -
-
- Index (@Indexes.Count()) - @foreach (string Index in Indexes) - { -
@Index
- } -
-
- Column (@Columns.Count()) - @foreach (EbDbExplorerColumn Column in Columns) - { + var schema = table_kvp.Value.Schema; + if (!schemaGroups.ContainsKey(schema)) + { + schemaGroups[schema] = new List>(); + } + schemaGroups[schema].Add(table_kvp); + } + + // Get function collection + var functions = ViewBag.Tables.FunctionCollection as List ?? new List(); + + // Render the schema groups with tables and functions + foreach (var schemaGroup in schemaGroups) + { + var schema = schemaGroup.Key; + var tables = schemaGroup.Value; +
+ Schema: @schema +
+ Tables (@tables.Count) + @foreach (var Table_kvp in tables) + { +
+ @{ + EbDbExplorerTable table = Table_kvp.Value; + List Indexes = table.Index; + List Columns = table.Columns; + int constraintCount = Columns.Count(c => !string.IsNullOrEmpty(c.ColumnKey) && !string.IsNullOrEmpty(c.ConstraintName)); + + } + + @Table_kvp.Key + +
+ Indexes (@Indexes.Count) + @foreach (string Index in Indexes) + { +
+ @Index +
+ } +
+ +
- @{ if (Column.ColumnKey == "Primary key") - { } - else if (Column.ColumnKey == "Foreign key") - { } - if (Column.ColumnType == "integer" || Column.ColumnType == "numeric") - { - - } - else if (Column.ColumnType == "text" || Column.ColumnType == "character") - { - - } - if (Column.ColumnType == "timestamp without time zone") + + Columns (@Columns.Count) + + @foreach (var Column in Columns.OrderBy(c => c.ColumnName)) + { +
+ + @{ + if (Column.ColumnKey == "Primary key") + { + + } + else if (Column.ColumnKey == "Foreign key") + { + + } + + string iconClass = null; + if (Column.ColumnType == "integer") + { + iconClass = "fa fa-sort-numeric-asc"; + } + else if (Column.ColumnType == "numeric") + { + iconClass = "fa fa-hashtag"; + } + else if (Column.ColumnType == "text") + { + iconClass = "fa fa-font"; + } + else if (Column.ColumnType == "character") + { + iconClass = "fa fa-quote-left"; + } + else if (Column.ColumnType == "boolean") + { + iconClass = "fa fa-check-square"; + } + else if (Column.ColumnType == "character varying") + { + iconClass = "fa fa-text-width"; + } + else if (Column.ColumnType == "smallint") + { + iconClass = "fa fa-sort-amount-down"; + } + else if (Column.ColumnType == "bigint") + { + iconClass = "fa fa-sort-amount-up"; + } + else if (Column.ColumnType == "date") + { + iconClass = "fa fa-calendar-day"; + } + else if (Column.ColumnType == "timestamp without time zone") + { + iconClass = "fa fa-calendar"; + } + + if (iconClass != null) + { + + } + } + + @Column.ColumnName @Column.ColumnTable + +
+ } +
+ +
+ + Constraints (@constraintCount) + + @foreach (EbDbExplorerColumn Column in Columns) + { + if (!string.IsNullOrEmpty(Column.ColumnKey) && !string.IsNullOrEmpty(Column.ConstraintName)) { - +
+ + + @{ + if (Column.ColumnKey == "Primary key") + { + + } + else if (Column.ColumnKey == "Foreign key") + { + + } + else if (Column.ColumnKey == "Unique key") + { + + } + } + + @Column.ConstraintName (@Column.ColumnKey) + +
} - } @Column.ColumnName @Column.ColumnTable + }
- } -
- } + +
+ } +
+
+ @{ + List Functions = ViewBag.Tables.FunctionCollection; + } + + + Functions (@Functions.Count) + + + @foreach (var function in Functions) + { +
+ + @function.FunctionName + +
+ } + +
+
} } -
-
+
+
+ + + - @{ List Functions = ViewBag.Tables.FunctionCollection; - Functions ( @Functions.Count() ) - foreach (EbDbExplorerFunctions Function in Functions) - { -
- @{ - @Function.FunctionName + + -
- @Function.FunctionQuery -
- } + + + + + //function modal + + + + + + + + + + } else { - + $(document).ready(function () { + EbMessage("show", { Message: '@ViewBag.Message', Background: "red" }); + setTimeout(function () { + location.reload(true); + }, 5000); + }); + + + } } diff --git a/Views/Shared/Components/ObjectDashboard/Default.cshtml b/Views/Shared/Components/ObjectDashboard/Default.cshtml index b395bbd7b..54cc7d77a 100644 --- a/Views/Shared/Components/ObjectDashboard/Default.cshtml +++ b/Views/Shared/Components/ObjectDashboard/Default.cshtml @@ -30,6 +30,9 @@ @*dona*@ + + +
@@ -151,11 +154,12 @@ } if ((ViewBag.wc == "uc" || ViewBag.wc == "dc") && (ViewBag.Env != "Production" || ViewBag.email == "support@expressbase.com")) { - } + }
diff --git a/Views/Shared/Components/PageHeaderCommon/Default.cshtml b/Views/Shared/Components/PageHeaderCommon/Default.cshtml index 533cc9ee6..a61fa3494 100644 --- a/Views/Shared/Components/PageHeaderCommon/Default.cshtml +++ b/Views/Shared/Components/PageHeaderCommon/Default.cshtml @@ -3,6 +3,9 @@ @using Newtonsoft.Json; @using ExpressBase.Security; @using ExpressBase.Common.Helpers; + + + @{ string Logourl = "/images/logo/" + ViewBag.cid + ".png"; diff --git a/Views/Shared/TicketRisingWindow.cshtml b/Views/Shared/TicketRisingWindow.cshtml index 9d45f6d42..b5af25c71 100644 --- a/Views/Shared/TicketRisingWindow.cshtml +++ b/Views/Shared/TicketRisingWindow.cshtml @@ -1,12 +1,12 @@  -
+
-
-

+
+

Hello! Welcome to Expressbase Service Desk.

@@ -32,14 +32,14 @@
-