public int UndoUpdate(LogWebRequestDataModel 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 logwebrequest SET Important = {0} ", nullString));
                    string where = string.Format("WHERE TimeStamp = \"{0}\" AND WebRequestID = GuidToBinary(\"{1}\") AND UserID = GuidToBinary(\"{2}\") AND RawURL = \"{3}\"; ",
                                                 sqlFormattedTimeStamp, LogToUpdate.WebRequestID, LogToUpdate.UserID, LogToUpdate.RawURL);
                    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(LogWebRequestDataModel 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 logwebrequest SET Important = {0} ", username));
                        string where = string.Format("WHERE TimeStamp = \"{0}\" AND WebRequestID = GuidToBinary(\"{1}\") AND UserID = GuidToBinary(\"{2}\") AND RawURL = \"{3}\"; ",
                                                     sqlFormattedTimeStamp, LogToUpdate.WebRequestID, LogToUpdate.UserID, LogToUpdate.RawURL);
                        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
 internal static LogWebRequestPoco ToPoco(this LogWebRequestDataModel source)
 {
     if (null != source)
     {
         return(new LogWebRequestPoco
         {
             TimeStamp = source.TimeStamp,
             WebRequestID = GuidMapper.Map(source.WebRequestID),
             UserID = GuidMapper.Map(source.UserID),
             RawURL = source.RawURL,
             Parameters = source.Parameters,
             Important = source.Important,
         });
     }
     return(null);
 }