// GET: AdminRegistrations
        public ActionResult Index()
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            using (var db = new glsoverviewdbEntities())
            {
                var registrations = db.registrations.Include(r => r.car).Include(r => r.employee).OrderByDescending(r => r.Date);
                return View(registrations.ToList());
            }
        }
Example #2
0
        // NB: This code is run on EVERY page view, until a car is parked on that day!
        // Should only run once pr. day, but we couldn't fix this in time.
        public static void ResetCars()
        {
            using (var _db = new glsoverviewdbEntities())
            {
                var lastAddedReg = _db.registrations.Max(r => r.Date);
                if (lastAddedReg.Date >= DateTime.Today) return;

                foreach (var car in _db.cars)
                    car.Status = (int)StatusTypes.Arrived;

                _db.SaveChanges();
            }
        }
        public ActionResult Delete(int? id)
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            if (id == null)
                return HttpNotFound();

            using (glsoverviewdbEntities db = new glsoverviewdbEntities())
            {
                employee emp = db.employees.Find(id);
                return View(emp);
            }
        }
Example #4
0
        public ActionResult RegistrationChecked(int? id)
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            if (id == null)
                return HttpNotFound();

            using (var db = new glsoverviewdbEntities())
            {
                var reg = db.registrations.Find(id);
                reg.CommentHandled = true;
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }
Example #5
0
        public ActionResult Index(AdminModel am)
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            using (var db = new glsoverviewdbEntities())
            {
                var registrationList = db.registrations
                    .Include(r => r.car)
                    .Include(e => e.employee)
                    .Where(r => !(r.Comment == null || r.Comment.Trim() == string.Empty)
                                && r.CommentHandled == false)
                    .ToList();
                am.RegistrationList = registrationList;
            }

            am.Employee = LoginController.CurrentUser();
            return View(am);
        }
        public ActionResult Create(employee emp)
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            if (emp == null)
                return HttpNotFound();

            using (glsoverviewdbEntities db = new glsoverviewdbEntities())
            {
                emp.Password = Sha1.Encode(emp.Password);

                db.employees.Add(emp);
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine(
                            "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                ve.PropertyName,
                                eve.Entry.CurrentValues.GetValue<object>(ve.PropertyName),
                                ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }

            return RedirectToAction("Index", "AdminEmployees");
        }
Example #7
0
        public ActionResult Index()
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            using (var _db = new glsoverviewdbEntities())
            {
                var cars = _db.cars.ToList();
                return View(cars);
            }
        }
        public ActionResult Edit(employee emp)
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            if (emp == null)
                return HttpNotFound();

            using (glsoverviewdbEntities db = new glsoverviewdbEntities())
            {
                emp.Password = Sha1.Encode(emp.Password);

                db.Entry(emp).State = EntityState.Modified;
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }
        public ActionResult Edit(int id)
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            using (glsoverviewdbEntities db = new glsoverviewdbEntities())
            {
                employee emp = db.employees.Find(id);
                return View(emp);
            }
        }
        public ActionResult PostDelete(int? id)
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            if (id == null)
                return HttpNotFound();

            using (glsoverviewdbEntities db = new glsoverviewdbEntities())
            {
                employee emp = db.employees.Find(id);
                db.employees.Remove(emp);
                db.SaveChanges();
            }

            return RedirectToAction("Index");
        }
        // GET: AdminEmployee
        public ActionResult Index()
        {
            if (!LoginController.IsAdmin())
                return View("~/Views/Login/Index.cshtml");

            var resList = new List<employee>();
            using (var db = new glsoverviewdbEntities())
            {
                var query = from e in db.employees
                            orderby e.Name descending
                            select e;
                foreach (var emp in query)
                {
                    resList.Add(emp);
                }
            }
            return View(resList);
        }