title: Updation on DB with the different categories in Asp.net MVC
body: <p>I am creating a project related to Leave Absence. Leave will be maintained &amp; manipulated according to the different categories.</p>
  
  <p>Every Flow of concept is working, except calculating Leave Days &amp; Showing Balance.</p>
  
  <p>I have created a Model Named,
  <strong>LeaveReq.CS</strong></p>
  
  <pre><code>public class LeaveReq
  {
      public int ID {get; set; }
  
      [Display(Name = "Employee Name")]
      public string emp_name { get; set; }
  
      [Display(Name = "Requested Day")]
      public string day_ctg { get; set; }
  
      [Display(Name = "Start Date")]
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:MM-dd-yyyy}", ApplyFormatInEditMode = true)]
      public DateTime startdt { get; set; }
  
      [Display(Name = "End Date")]
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:MM-dd-yyyy}", ApplyFormatInEditMode = true)]
      public DateTime enddt { get; set; }
  
      [Display(Name = "Time-Off Category")]
      public string category { get; set; }
  
      [Display(Name = "Applied On")]
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:MM-dd-yyyy}", ApplyFormatInEditMode = true)]
      public DateTime apply { get; set; }
  
      [Display(Name = "Balance")]
      public string bal { get; set; }
  
  }
  </code></pre>
  
  <p>and The screen would like, </p>
  
  <p><a href="https://i.stack.imgur.com/DBZvG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DBZvG.png" alt="Apply Leave"></a></p>
  
  <p>I have created a Model Named, <strong>TimeOffSettigs.CS</strong></p>
  
  <pre><code>public class TimeOffSettigs
  {
      public int ID { get; set; }
  
      [Display(Name = "Time-Off Type")]
      [StringLength(30, MinimumLength = 3)]
      public string type { get; set; }
  
      [Display(Name = "Time-Off Category")]
      public string category { get; set; }
  
      [Display(Name = "Maximum Allowance")]
      public int allowance { get; set; }
  }
  </code></pre>
  
  <p>The Screen Would, Look Like
  <a href="https://i.stack.imgur.com/yviMp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yviMp.png" alt="TimeOffSettings"></a></p>
  
  <p>Basic Concept is that, When an employee applies for Leave in a category. His Balance leave should be shown. On applying, Certain allowance should be deducted from his remaining balance.</p>
  
  <p>For Example. If I am applying leave in Vacation &amp; Full Day (8Hrs).
  Allowance for Vacation is 80hrs.
  On applying leave for First Time. My balance be stored as (80-8) 72Hours.
  On Applying next time as half a day(4hrs). My Balance should be stored as (72-4) 68Hrs in DB</p>
  
  <p>I have written a code, for this concept in <strong>Controller.CS</strong></p>
  
  <pre><code>    [HttpPost, ActionName("Approve")]
      [ValidateAntiForgeryToken]
      public ActionResult LvDetailsConfirmed(int id)
      {
          LeaveReq levreq = dblv.Leave_Dts.Find(id);
          TimeOffSettigs timesettings = dbts.policy_tbl.Find(id);
  
          if (levreq.bal == null)
          {
              if (levreq.day_ctg == "Full Day")
              {
                  var bal_full = 8;
                  levreq.bal = (timesettings.allowance - bal_full).ToString();
              }
              else if (levreq.day_ctg == "Partial Day")
              {
                  var bal_par = 4;
                  levreq.bal = (timesettings.allowance - bal_par).ToString();
              }
              else
              {
                  var timespan = levreq.enddt.Subtract(levreq.startdt);
                  var dayscalc = timespan.Days;
                  var bal_mul = 8 * dayscalc;
                  levreq.bal = (timesettings.allowance - bal_mul).ToString();
              }
          }
  
          else
          {
              if (levreq.day_ctg == "Full Day")
              {
                  var bal_full = 8;
                  levreq.bal = (Convert.ToInt32(levreq.bal) - bal_full).ToString();
              }
              else if (levreq.day_ctg == "Partial Day")
              {
                  var bal_par = 4;
                  levreq.bal = (Convert.ToInt32(levreq.bal) - bal_par).ToString();
              }
              else
              {
                  var timespan = levreq.enddt.Subtract(levreq.startdt);
                  var dayscalc = timespan.Days;
                  var bal_mul = 8 * dayscalc;
                  levreq.bal = (Convert.ToInt32(levreq.bal) - bal_mul).ToString();
              }
          }
  
          if (ModelState.IsValid)
          {
              dblv.Entry(levreq).State = EntityState.Modified;
              dblv.SaveChanges();
              return RedirectToAction("ELeave");
          }
          return View(levreq);
  </code></pre>
  
  <p>Approval/Request Screen will be looking like,</p>
  
  <p><a href="https://i.stack.imgur.com/gs1r9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gs1r9.png" alt="Approve/Reject"></a></p>
  
  <p>On clicking Approve, Balance should be Deducted.
  On Clicking Reject, Balance shouldnt be deducted.</p>
  
  <p>Don't know, what is the wrong I did in controller. whenever I press Approve, Nothing change happening in DB.</p>
  
  <p>This is the Approval Button Code</p>
  
  <pre><code>@using (Html.BeginForm())
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-actions no-color"&gt;
          &lt;input type="submit" value="Approve" class="btn btn-default" name="aprbtn" /&gt; |
          &lt;input type="submit" value="Reject" class="btn btn-default" name="rejbtn"/&gt;
          @Html.ActionLink("Back to List", "ELeave")
      &lt;/div&gt;
  }
  </code></pre>