public static ILimitService GetLimitService()
        {
            ApplicationContext context = GetContext();
            ILimitService      service = new LimitService(context);

            return(service);
        }
示例#2
0
        /* public ActionResult Details()
         * {
         *
         *   try
         *   {
         *       if (!IsLogged()) { return RedirectToAction("Login", "Account"); }
         *
         *       using (ISession session = database.MakeSession())
         *       {
         *           ValidateReaderAndEmployeeForbiddenAccess(session);
         *
         *           LimitService limitService = LimitService.getInstance();
         *           Limit limit = limitService.getLimit();
         *           return View(limit);
         *       }
         *   }
         *   catch (UnauthorizedAccessException)
         *   {
         *       return RedirectToAction("Forbidden", "Error");
         *   }
         *   catch (Exception)
         *   {
         *       return RedirectToAction("Index", "Home");
         *   }
         * }*/


        public ActionResult Edit()
        {
            try
            {
                if (!IsLogged())
                {
                    return(RedirectToAction("Login", "Account"));
                }

                using (ISession session = database.MakeSession())
                {
                    ValidateReaderForbiddenAccess(session);

                    LimitService limitService = LimitService.getInstance();
                    Limit        limit        = limitService.getLimit();
                    return(View(limit));
                }
            }

            catch (UnauthorizedAccessException)
            {
                return(RedirectToAction("Forbidden", "Error"));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult Reserve(int copyId)
        {
            try
            {
                if (!IsLogged())
                {
                    return(RedirectToAction("Login", "Account"));
                }
                using (ISession session = database.MakeSession())
                {
                    ValidateAdminAndEmployeeForbiddenAccess(session);
                    LimitService limitService     = LimitService.getInstance();
                    var          reader           = GetReader(session);
                    var          userRentals      = session.QueryOver <Rental>().Where(x => x.Reader == reader).Where(x => x.Deleted == true).RowCount();
                    var          userReservations = session.QueryOver <Reservation>().Where(x => x.Reader == reader).RowCount();

                    if (userRentals + userReservations + 1 > limitService.getLimit().MaxAmountOfBooks)
                    {
                        return(RedirectToAction("Cart", "Account"));
                    }
                    var copy = session.Get <Copy>(copyId);
                    copy.Status = Enums.Status.RENTED;
                    var timeLimit   = limitService.getLimit().MaxDaysOfRental;
                    var reservation = new Reservation()
                    {
                        Copy     = copy,
                        Reader   = reader,
                        DateFrom = DateTime.Today.ToString("dd.MM.yyyy"),
                        DateTo   = DateTime.Today.AddDays(timeLimit).ToString("dd.MM.yyyy")
                    };

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.SaveOrUpdate(reservation);
                        session.SaveOrUpdate(copy);
                        session.Flush();
                        transaction.Commit();
                    }
                    DeleteFromSession(copyId);


                    return(RedirectToAction("Cart", "Account"));
                }
            }
            catch (UnauthorizedAccessException)
            {
                return(RedirectToAction("Forbidden", "Error"));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#4
0
 public ActionResult Edit(Limit limit)
 {
     try
     {
         using (ISession session = database.MakeSession())
         {
             LimitService.getInstance().setLimit(limit.MaxDaysOfRental, limit.MaxAmountOfBooks);
         }
         return(RedirectToAction("Edit", "Limit"));
     }
     catch
     {
         return(View());
     }
 }
示例#5
0
        public ActionResult Add(int reservationId)
        {
            try
            {
                if (!IsLogged())
                {
                    return(RedirectToAction("Login", "Account"));
                }
                using (ISession session = database.MakeSession())
                {
                    ValidateReaderForbiddenAccess(session);
                    var          reservation  = session.Get <Reservation>(reservationId);
                    var          copy         = reservation.Copy;
                    LimitService limitService = LimitService.getInstance();
                    var          limit        = limitService.getLimit().MaxDaysOfRental;
                    var          rental       = new Rental()
                    {
                        Copy                = copy,
                        Reader              = reservation.Reader,
                        DateFrom            = DateTime.Now.ToString("dd.MM.yyyy"),
                        DateTo              = DateTime.Now.AddDays(limit).ToString("dd.MM.yyyy"),
                        Deleted             = false,
                        CloseReturnMailSent = false,
                        LateReturnMailSent  = false
                    };
                    copy.Status = Enums.Status.RENTED;

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        session.SaveOrUpdate(rental);
                        session.Delete(reservation);
                        session.SaveOrUpdate(copy);
                        session.Flush();
                        transaction.Commit();
                    }
                    return(RedirectToAction("Index", "Reservation"));
                }
            }
            catch (UnauthorizedAccessException)
            {
                return(RedirectToAction("Forbidden", "Error"));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult ReserveAll()
        {
            try
            {
                if (!IsLogged())
                {
                    return(RedirectToAction("Login", "Account"));
                }
                using (ISession session = database.MakeSession())
                {
                    ValidateAdminAndEmployeeForbiddenAccess(session);
                    if (Session[SESSION_CART] == null)
                    {
                        return(RedirectToAction("Cart", "Account"));
                    }

                    LimitService limitService     = LimitService.getInstance();
                    var          reader           = GetReader(session);
                    var          userRentals      = session.QueryOver <Rental>().Where(x => x.Reader == reader).Where(x => x.Deleted == true).RowCount();
                    var          userReservations = session.QueryOver <Reservation>().Where(x => x.Reader == reader).RowCount();


                    var sessionList = (List <int>)Session[SESSION_CART];
                    if (userRentals + userReservations + sessionList.Count > limitService.getLimit().MaxAmountOfBooks)
                    {
                        return(RedirectToAction("Cart", "Account"));
                    }

                    var timeLimit = limitService.getLimit().MaxDaysOfRental;
                    //@TODO czy to bedzie inny limit?

                    var reservations = new List <Reservation>();
                    var copies       = new List <Copy>();
                    foreach (var id in Session[SESSION_CART] as List <int> )
                    {
                        var copy = session.Get <Copy>(id);
                        copy.Status = Enums.Status.RENTED;
                        copies.Add(copy);
                        var reservation = new Reservation()
                        {
                            Copy     = copy,
                            Reader   = reader,
                            DateFrom = DateTime.Today.ToString("dd.MM.yyyy"),
                            DateTo   = DateTime.Today.AddDays(timeLimit).ToString("dd.MM.yyyy")
                        };
                        reservations.Add(reservation);
                    }
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        foreach (var reservation in reservations)
                        {
                            session.SaveOrUpdate(reservation);
                            session.Flush();
                        }

                        foreach (var copy in copies)
                        {
                            session.SaveOrUpdate(copy);
                            session.Flush();
                        }
                        transaction.Commit();
                    }

                    ClearSession();

                    return(RedirectToAction("Cart", "Account"));
                }
            }
            catch (UnauthorizedAccessException)
            {
                return(RedirectToAction("Forbidden", "Error"));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
 public void SetUp()
 {
     _limitRepository = Substitute.For <ILimitRepository>();
     _sut             = new LimitService(_limitRepository);
 }
示例#8
0
 public LimitController(LimitService limitService, SchedulearnContext schedulearnContext)
 {
     _limitService       = limitService;
     _schedulearnContext = schedulearnContext;
 }