public static void RemoveResourceReservationFromDB(RESOURCES_RESERVATIONS model)
 {
     using (var context = new Contextt())
     {
         context.ResourceReservationContext.Remove(model);
         context.SaveChanges();
     };
 }
        public RESOURCES_RESERVATIONS GetResourcesReservationByReservID(int ReservationID)
        {
            RESOURCES_RESERVATIONS reservation = new RESOURCES_RESERVATIONS();

            using (var context = new APSITestDbEntities1())
            {
                reservation = context.RESOURCES_RESERVATIONS.First(r => r.ResourceResId == ReservationID);
            }
            return(reservation);
        }
        public ActionResult ResourceReservation(RESOURCES_RESERVATIONS model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            _resourceReservation.EmployeeId  = GetLoggedUserId();
            _resourceReservation.ProjectCode = model.ProjectCode;
            _resourceReservation.BeginDate   = model.BeginDate;
            _resourceReservation.EndDate     = model.EndDate;

            var      ReservationList    = dbOperations.GetResourcesReservation(_resourceReservation.ResourceId);
            TimeSpan beginDifference    = new TimeSpan();
            TimeSpan endDifference      = new TimeSpan();
            TimeSpan beginEndDifference = new TimeSpan();
            TimeSpan EndbeginDifference = new TimeSpan();
            TimeSpan zero             = new TimeSpan(0, 0, 0, 0);
            var      sequenceBeginEnd = model.EndDate - model.BeginDate;

            if (sequenceBeginEnd < zero)
            {
                return(RedirectToAction("WrongEndBeginDate"));
            }
            foreach (var reservation in ReservationList)
            {
                beginDifference    = reservation.BeginDate - _resourceReservation.BeginDate;
                endDifference      = reservation.EndDate - _resourceReservation.EndDate;
                beginEndDifference = reservation.BeginDate - _resourceReservation.EndDate;
                EndbeginDifference = reservation.EndDate - _resourceReservation.BeginDate;

                if ((beginEndDifference <= zero && endDifference >= zero) || (endDifference <= zero && EndbeginDifference >= zero) || (beginEndDifference <= zero && beginDifference >= zero))
                {
                    return(RedirectToAction("ResourceIsReserved"));
                }
            }
            DbOperations.AddResourceReservationToDB(_resourceReservation);
            return(RedirectToAction("ResourceList"));
        }
        public ActionResult DeleteResourceReservation(int id)
        {
            _resourceReservation = dbOperations.GetResourcesReservationByReservID(id);

            return(View(_resourceReservation));
        }