public int UndoUpdate(CombinedLogControllerActionDataModel 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 logcontrolleraction SET Important = {0} ", nullString));
                    string where = string.Format("WHERE TimeStamp = \"{0}\" AND WebRequestID = GuidToBinary(\"{1}\") AND ControllerName = \"{2}\" AND ActionName = \"{3}\" AND UserID = GuidToBinary(\"{4}\"); ",
                                                 sqlFormattedTimeStamp, LogToUpdate.WebRequestID, LogToUpdate.ControllerName, LogToUpdate.ActionName, LogToUpdate.UserID);
                    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(CombinedLogControllerActionDataModel 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 logcontrolleraction SET Important = {0} ", username));
                        string where = string.Format("WHERE TimeStamp = \"{0}\" AND WebRequestID = GuidToBinary(\"{1}\") AND ControllerName = \"{2}\" AND ActionName = \"{3}\" AND UserID = GuidToBinary(\"{4}\"); ",
                                                     sqlFormattedTimeStamp, LogToUpdate.WebRequestID, LogToUpdate.ControllerName, LogToUpdate.ActionName, LogToUpdate.UserID);
                        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);
        }
Example #3
0
        public JsonResult MarkUnimportant([System.Web.Http.FromBody] CombinedLogControllerActionDataModel logToUpdate)
        {
            logToUpdate.Important = null;
            int updatePerformed = m_logControllerActionRepository.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" }));
            }
        }
Example #4
0
        public JsonResult UpdateImportance(string username, [System.Web.Http.FromBody] CombinedLogControllerActionDataModel logToUpdate)
        {
            logToUpdate.Important = username;
            int updatePerformed = m_logControllerActionRepository.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(";");
                    CombinedLogControllerActionPoco      poco  = db.FirstOrDefault <CombinedLogControllerActionPoco>(sql);
                    CombinedLogControllerActionDataModel 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));
        }