Ejemplo n.º 1
0
        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

            LogException exc = new LogException();

            exc.HandleException(Server.GetLastError());
            string servername;
            string HostName = "";

            if (HttpContext.Current.Request.IsSecureConnection)
            {
                servername = HttpUtility.UrlEncode(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]);
                HostName   = "https://" + servername + "/";
            }
            else
            {
                servername = HttpUtility.UrlEncode(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]);
                HostName   = "http://" + servername + "/";
            }
            string ErrorPage = HostName + "pages-404.html";

            if (servername.ToLower() != "localhost")
            {
                Response.Redirect(ErrorPage);
            }
        }
Ejemplo n.º 2
0
 protected bool Upsert()
 {
     try
     {
         var entities = Variable.CurrentEntities;
         var dbSet    = entities.Set <BaseModel <T> >();
         dbSet.AddOrUpdate(this);
         return(true);
     }
     catch (Exception exception)
     {
         LogException.HandleException(exception);
         return(false);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a new record to data base. It doesn't check for record existance.
 /// </summary>
 /// <returns></returns>
 protected BaseModel <T> Add()
 {
     try
     {
         var entities = Variable.CurrentEntities;
         var dbSet    = entities.Set <BaseModel <T> >();
         var result   = dbSet.Add(this);
         entities.SaveChanges();
         return(result);
     }
     catch (Exception exception)
     {
         LogException.HandleException(exception);
         return(null);
     }
 }
Ejemplo n.º 4
0
 protected bool Update()
 {
     try
     {
         var entities = Variable.CurrentEntities;
         var dbSet    = entities.Set <BaseModel <T> >();
         var original = dbSet.Find(this);
         entities.Entry(original).CurrentValues.SetValues(this);
         entities.SaveChanges();
         return(true);
     }
     catch (Exception exception)
     {
         LogException.HandleException(exception);
         return(false);
     }
 }
Ejemplo n.º 5
0
 protected BaseModel <T> Save()
 {
     try
     {
         var entities = Variable.CurrentEntities;
         var dbSet    = entities.Set <BaseModel <T> >();
         var original = dbSet.Find(Id);
         if (original == null)
         {
             original = dbSet.Add(this);
         }
         else
         {
             entities.Entry(original).CurrentValues.SetValues(this);
         }
         entities.SaveChanges();
         return(original);
     }
     catch (Exception exception)
     {
         LogException.HandleException(exception);
         return(null);
     }
 }