コード例 #1
0
 /// <summary>
 /// This method adds absence to DbSet and then save changes to database.
 /// </summary>
 /// <param name="absence">Absence.</param>
 /// <returns>True if added, false if not.</returns>
 public bool AddAbsence(vwAbsence absence)
 {
     try
     {
         using (HotelEntities context = new HotelEntities())
         {
             tblAbsence newAbsence = new tblAbsence
             {
                 FirstDay = absence.FirstDay,
                 LastDay  = absence.LastDay,
                 Status   = "on hold",
                 Reason   = absence.Reason,
                 UserId   = absence.UserId
             };
             context.tblAbsences.Add(newAbsence);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
コード例 #2
0
 /// <summary>
 /// This method changes status of absence to rejected.
 /// </summary>
 /// <param name="request">Request to be rejected.</param>
 /// <returns>True if rejected, false if not.</returns>
 public bool RejectRequest(vwAbsence request)
 {
     try
     {
         using (HotelEntities context = new HotelEntities())
         {
             tblAbsence requestToReject = context.tblAbsences.Where(x => x.AbsenceId == request.AbsenceId).FirstOrDefault();
             requestToReject.Status = "rejected";
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }