Example #1
0
        public ActionResult CreateAbsence(AbsenceViewModel avm)
        {
            try
            {
                if (HttpContext.Session.GetInt32("userId") > 0)
                {
                    if (avm.StartDate == null)
                    {
                        avm.StartDate = DateTime.Today;
                    }
                    if (avm.EndDate == null)
                    {
                        avm.StartDate = avm.StartDate;
                    }
                    avm.Dictionary = new Dictionary(HttpContext.Session.GetInt32("language"));
                    if (reservationBll.ShowAllReservations().Where(r1 => r1.UserId == avm.UserId).FirstOrDefault(r => (r.StartDate >= avm.StartDate && r.StartDate <= avm.EndDate) || (r.EndDate >= avm.StartDate && r.EndDate <= avm.EndDate)) == null &&
                        reservationBll.ShowAllReservations().Where(r1 => r1.UserId == avm.UserId).FirstOrDefault(r => (avm.StartDate >= r.StartDate && avm.StartDate <= r.EndDate) || (avm.EndDate >= r.StartDate && avm.EndDate <= r.EndDate)) == null)
                    {
                        Absence absence = new Absence
                        {
                            UserId       = avm.UserId,
                            StartDate    = avm.StartDate,
                            EndDate      = avm.EndDate,
                            Description  = avm.Description,
                            CreationDate = DateTime.Now,
                            Creator      = HttpContext.Session.GetInt32("userId"),
                            Status       = 0,
                            StatusDate   = DateTime.Now
                        };

                        if (HttpContext.Session.GetInt32("admin") > 0 || avm.UserId == absence.Creator)
                        {
                            absenceBll.CreateAbsence(absence);
                        }
                    }
                    else
                    {
                        avm.ConflictReservatie = true;
                    }
                }

                avm.Absences            = new AbsenceFE().GetAbsensesFE(absenceBll.ShowAllAbsences().Where(a => a.UserId == avm.UserId && a.EndDate >= DateTime.Today));
                avm.UserCode            = userBll.GetUserById(avm.UserId).Login;
                ViewData["sessionData"] = new int?[] { HttpContext.Session.GetInt32("admin"), HttpContext.Session.GetInt32("language") };
                return(RedirectToAction(nameof(Index), avm));
            }
            catch
            {
                ViewData["sessionData"] = new int?[] { HttpContext.Session.GetInt32("admin"), HttpContext.Session.GetInt32("language") };
                return(RedirectToAction(nameof(Index), avm));
            }
        }
        public IActionResult Index(ReservationViewModel rvm)
        {
            try
            {
                ViewData["sessionData"] = new int?[] { HttpContext.Session.GetInt32("admin"), HttpContext.Session.GetInt32("language") };
                this.rvm       = rvm;
                activeUser     = userBll.GetUserById((long)HttpContext.Session.GetInt32("userId"));
                rvm.ActiveUser = activeUser;
                rvm.Dictionary = new Dictionary(HttpContext.Session.GetInt32("language"));
                if (rvm.UserCode != null)
                {
                    rvm.User = userBll.ShowAllUsers().FirstOrDefault(u => u.Login == rvm.UserCode);
                    if (rvm.User == null)
                    {
                        ViewData["message2"] = "User not found";
                        rvm.User             = activeUser;
                        rvm.UserCode         = activeUser.Login;
                    }
                }
                else
                {
                    rvm.User     = activeUser;
                    rvm.UserCode = activeUser.Login;
                }

                rvm.UserId = rvm.User.UserId;
                rvm.Start  = DateTime.Today;
                rvm.End    = DateTime.Today;
                IEnumerable <Reservation> reservations = reservationBll.ShowAllReservations().Where(r => r.UserId == rvm.User.UserId && r.EndDate >= DateTime.Today);
                rvm.Reservations = new ReservationFE().GetReservations(flexDeskBll, reservations);

                ViewData["message"] = rvm.Message;
                return(View(rvm));
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #3
0
 public IEnumerable <Reservation> Get()
 {
     //return reservationProvider.Get();
     return(reservationBll.ShowAllReservations());
 }