Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        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");
        }