public int UndoUpdate(CombinedLogExceptionDataModel LogToUpdate) { try { using (AsignioDatabase db = new AsignioDatabase(ConnectionStringName)) { string sqlFormattedTimeStamp = LogToUpdate.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss"); PetaPoco.Sql sql = new PetaPoco.Sql(); string nullString = "null"; sql.Append("SET SQL_SAFE_UPDATES = 0; "); sql.Append(string.Format("UPDATE logexception SET Important = {0} ", nullString)); string where = string.Format("WHERE TimeStamp = \"{0}\" AND WebRequestID = GuidToBinary(\"{1}\") AND UserID = GuidToBinary(\"{2}\") AND MethodName = \"{3}\" AND Source = \"{4}\"; ", sqlFormattedTimeStamp, LogToUpdate.WebRequestID, LogToUpdate.UserID, LogToUpdate.MethodName, LogToUpdate.Source); sql.Append(where); sql.Append("SET SQL_SAFE_UPDATES = 1; "); db.Execute(sql); return 1; } } catch (Exception ex) { string errorMessage = ex.Message; return 0; } finally { } }
public JsonResult MarkUnimportant([System.Web.Http.FromBody] CombinedLogExceptionDataModel logToUpdate) { logToUpdate.Important = null; int updatePerformed = m_logExceptionRepository.UndoUpdate(logToUpdate); if (updatePerformed == 1) { string success = "Successfully unmarked as important"; return(Json(new { IsCreated = true, Content = success })); } else { return(Json(new { IsCreated = false, ErrorMessage = "Error" })); } }
public JsonResult UpdateImportance(string username, [System.Web.Http.FromBody] CombinedLogExceptionDataModel logToUpdate) { logToUpdate.Important = username; int updatePerformed = m_logExceptionRepository.Update(logToUpdate, username); if (updatePerformed == 1) //update successful { string success = "Successfully marked as important"; return(Json(new { IsCreated = true, Content = success })); } else //update failed - generally because the user entered email was not in the user database { return(Json(new { IsCreated = false, ErrorMessage = "Email entered by the user was not found in user database" })); } }
public int Update(CombinedLogExceptionDataModel LogToUpdate, string username) { try { using (AsignioDatabase db = new AsignioDatabase(ConnectionStringName)) { Byte[] bytes = new Byte[16]; Guid allZeros = new Guid(bytes); Guid UserID = GetUserIDFromUsername(username); if (UserID != allZeros) { if (username.Contains("@")) //format email { string[] sections = username.Split(new[] { '@' }); sections[1] = sections[1].Insert(0, "@@"); username = string.Join("", sections); } string sqlFormattedTimeStamp = LogToUpdate.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss"); PetaPoco.Sql sql = new PetaPoco.Sql(); username = string.Format("\"{0}\"", username); sql.Append("SET SQL_SAFE_UPDATES = 0; "); sql.Append(string.Format("UPDATE logexception SET Important = {0} ", username)); string where = string.Format("WHERE TimeStamp = \"{0}\" AND WebRequestID = GuidToBinary(\"{1}\") AND UserID = GuidToBinary(\"{2}\") AND MethodName = \"{3}\" AND Source = \"{4}\"; ", sqlFormattedTimeStamp, LogToUpdate.WebRequestID, LogToUpdate.UserID, LogToUpdate.MethodName, LogToUpdate.Source); sql.Append(where); sql.Append("SET SQL_SAFE_UPDATES = 1; "); db.Execute(sql); return 1; } else { return 0; } } } catch (Exception ex) { string errorMessage = ex.Message; } finally { } return 0; }
public Guid GetUserIDFromUsername(string username) { try { using (AsignioDatabase db = new AsignioDatabase(ConnectionStringName)) { PetaPoco.Sql sql = new PetaPoco.Sql(); sql.Append("SELECT UserID"); sql.Append("from user"); if (username.Contains("@")) //format email { string[] sections = username.Split(new[] { '@' }); sections[1] = sections[1].Insert(0, "@@"); username = string.Join("", sections); } username = string.Format("\"{0}\" ", username); sql.Append(string.Format("WHERE EmailAddress = {0} ", username)); sql.Append(";"); CombinedLogExceptionPoco poco = db.FirstOrDefault<CombinedLogExceptionPoco>(sql); CombinedLogExceptionDataModel model = poco.ToModel(); if (model != null) { return model.UserID; } else { Byte[] allZeroByte = new Byte[16]; return new Guid(allZeroByte); } } } catch (Exception ex) { string errorMessage = ex.Message; } finally { } Byte[] bytes = new Byte[16]; return new Guid(bytes); }