Ejemplo n.º 1
0
        public ActionResult ReportById(int id)
        {
            var          dbS          = new DatabaseService();
            var          adS          = new ActiveDirectoryService();
            CoffeeReport coffeereport = null;

            if (Session["Guid"] == null)
            {
                ViewBag.Error   = "Must be logged in to generate report";
                ViewBag.Shownav = true;
                return(View("Report", coffeereport));
            }

            if (!adS.IsAdmin((Guid)Session["Guid"]))
            {
                ViewBag.Error   = "Must be an admin to generate reports. Sneaky sneaky.";
                ViewBag.Shownav = true;
                return(View("Report", coffeereport));
            }

            coffeereport = dbS.GetReport(id);

            if (coffeereport == null)
            {
                ViewBag.Error   = "That report doesn't exist";
                ViewBag.Shownav = true;
                return(View("Report", coffeereport));
            }

            return(View("Report", coffeereport));
        }
Ejemplo n.º 2
0
        public void SaveReport(CoffeeReport coffeereport)
        {
            using (var coffeeContext = new CoffeeContext())
            {
                coffeeContext.CoffeeReports.Add(coffeereport);

                coffeeContext.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public ActionResult Report(ReportRequest request)
        {
            var dbS          = new DatabaseService();
            var adS          = new ActiveDirectoryService();
            var usersList    = dbS.GetAllUsers().Where(p => p.Drink != null).ToList();
            var coffeereport = new CoffeeReport();

            var forDate     = request.forDate;
            var nextMeeting = request.nextMeeting;
            var userIds     = request.userIds;

            ViewBag.OrderDate = forDate.ToString("MMMM") + " " + forDate.GetReadable() + ", " + forDate.ToString("yyyy");
            ViewBag.Title     = "Coffee Order for " + ViewBag.OrderDate;
            ViewBag.Shownav   = false;

            if (Session["Guid"] == null)
            {
                ViewBag.Error   = "Must be logged in to generate report";
                ViewBag.Shownav = true;
                return(View(coffeereport));
            }

            if (!adS.IsAdmin((Guid)Session["Guid"]))
            {
                ViewBag.Error   = "Must be an admin to generate reports. Sneaky sneaky.";
                ViewBag.Shownav = true;
                return(View(coffeereport));
            }

            if (forDate.Date != dbS.GetMeeting().Date)
            {
                CoffeeReport rep = new DatabaseService().GetReport(forDate);
                ViewBag.Error = "Cannot Re-generate Report.";
                if (rep != null)
                {
                    ViewBag.Error += "To view the generated report go https://coffee.rezare.co.nz/Home/ReportById/" + rep.Id;
                }

                ViewBag.Shownav = true;
                return(View(coffeereport));
            }

            // Filter for users in this report
            foreach (var item in usersList)
            {
                if (userIds.Contains(item.Id))
                {
                    item.WillBeThere = true;
                }
            }

            foreach (var user in usersList)
            {
                int count = usersList.Count(u => u.FirstName == user.FirstName);
                if (count > 1)
                {
                    user.FirstName = $"{user.FirstName} {user.LastName.Substring(0, 1)}.";
                }

                if (!user.WillBeThere)
                {
                    continue;
                }

                var tempReports = coffeereport.Report;
                var report      = tempReports.FirstOrDefault(p => p.DrinkTypeId == user.Drink?.Id);
                if (report != null)
                {
                    report.Users.Add(new UserEntry {
                        FirstName = user.FirstName, LastName = user.LastName, Options = user.CoffeeOptions, UserId = user.Id
                    });
                }
                else
                {
                    tempReports.Add(new ReportStruct
                    {
                        DrinkTypeId = user.Drink.Id,
                        DrinkName   = user.Drink.Name,
                        Users       = new List <UserEntry> {
                            new UserEntry {
                                FirstName = user.FirstName, LastName = user.LastName, Options = user.CoffeeOptions, UserId = user.Id
                            }
                        }
                    });
                }
                coffeereport.Report = tempReports;
            }

            coffeereport.GeneratedOn    = DateTime.Now;
            coffeereport.GeneratedFor   = forDate;
            coffeereport.GeneratedBy_Id = dbS.GetUser(Session["Guid"].ToString()).Id;

            dbS.SaveReport(coffeereport);
            coffeereport.GeneratedBy = dbS.GetUser(Session["Guid"].ToString());

            // Update the next meeting date
            dbS.SetMeeting(nextMeeting);
            dbS.ClearWillBeThere();

            return(View(coffeereport));
        }