public int UndoUpdate(CombinedLogDataModel 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 log SET Important = {0} ", nullString));
                    string where = string.Format("WHERE TimeStamp = \"{0}\" AND LogID = GuidToBinary(\"{1}\") AND Level = \"{2}\" AND Source = \"{3}\" ; ",
                                                 sqlFormattedTimeStamp, LogToUpdate.LogID, LogToUpdate.Level, 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 int Update(CombinedLogDataModel LogToUpdate, string username)
        {
            try
            {
                using (AsignioDatabase db = new AsignioDatabase(ConnectionStringName))
                {
                    Byte[] bytes    = new Byte[16];
                    Guid   allZeros = new Guid(bytes);

                    Guid UserID = GetUserIDFromUsername(username); //checking if username is in the User table

                    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 log SET Important = {0} ", username));
                        string where = string.Format("WHERE TimeStamp = \"{0}\" AND LogID = GuidToBinary(\"{1}\") AND Level = \"{2}\" AND Source = \"{3}\" ; ",
                                                     sqlFormattedTimeStamp, LogToUpdate.LogID, LogToUpdate.Level, 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);
        }
예제 #3
0
        public JsonResult MarkUnimportant([System.Web.Http.FromBody] CombinedLogDataModel logToUpdate)
        {
            logToUpdate.Important = null;
            int updatePerformed = m_logRepository.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" }));
            }
        }
예제 #4
0
        public JsonResult UpdateImportance(string username, [System.Web.Http.FromBody] CombinedLogDataModel logToUpdate)
        {
            logToUpdate.Important = username;
            int updatePerformed = m_logRepository.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 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(";");
                    CombinedLogPoco      poco  = db.FirstOrDefault <CombinedLogPoco>(sql);
                    CombinedLogDataModel 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));
        }