title: Set a job to failed using Hangfire with ASP.NET?
body: <p>I have an ASP.NET app which sends emails whenever the user signs up in the web site. I'm using hangfire in order to manage the jobs and postal in order to send emails.</p>
  
  <p>It all works great, but here's the thing:</p>
  
  <p>I want the superuser to change how many times the APP can send the email before deleting the job. </p>
  
  <p>Here's my code</p>
  
  <pre><code>    public static void WelcomeUser(DBContexts.Notifications not)
      {
          try{
              var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
              var engines = new ViewEngineCollection();
              engines.Add(new FileSystemRazorViewEngine(viewsPath));
  
              Postal.EmailService service = new Postal.EmailService(engines);
  
              WelcomeUserMail welcomeUserMail = new WelcomeUserMail();
              welcomeUserMail.To = not.ReceiverEmail;
              welcomeUserMail.UserEmail = not.ReceiverEmail;
              welcomeUserMail.From = BaseNotification.GetEmailFrom();
  
              service.Send(welcomeUserMail);
          }
          catch(Exception e)
          {
              DBContexts.DBModel dbModel = new DBModel();
              DBContexts.Notifications notificacionBD =  dbModel.Notifications.Find(not.NotificationID);
  
              notificacionBD.Status = false;
              notificacionBD.Timestamp = DateTime.Now;
              notificacionBD.Error = e.Message;
  
              int numberOfRetriesAllowed = ParameterHelper.getNumberOfRetriesAllowed();
  
              if (notificacionBD.Retries &gt; numberOfRetriesAllowed)
              {
                  //In this case Hangfire won't put this job in the failed section but rather in the processed section.
                  dbModel.SaveChanges();
              }
              else
              {
                  notificacionBD.Retries++;
                  dbModel.SaveChanges();
  
                  throw new Exception(e.Message);
              }
          }
      }
  </code></pre>