示例#1
0
        public void releaseJob(Vaktir vakt)
        {

            var vaktToRelease =
            from v in vse.Vaktir
            where v.VaktID == vakt.VaktID
            select v;
            foreach (var v in vaktToRelease)
                v.isFree = true;

            try
            {
                vse.SaveChanges();
            }
            /*catch (System.Exception e)
            {
                System.Console.WriteLine(e);
            }*/
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                foreach (var validationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        System.Console.WriteLine("Property: {0} throws Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

        }
示例#2
0
        public bool takeJob(Vaktir vakt)
        {
            bool canWork = true;

            var vaktToTake =
            from v in vse.Vaktir
            where v.VaktID == vakt.VaktID
            select v;
            var checkvakt =
                from v in vse.Vaktir
                where v.Date == vakt.Date
                where v.PersonID == LoggedIn.username
                select v;

            foreach(var v in checkvakt)
            {
                if ((vakt.Start > v.Start && vakt.Start < v.End)&&(vakt.End > v.Start && vakt.End < v.End))
                    canWork = false;
            }
            if (canWork)
            {
                foreach (var v in vaktToTake)
                {
                    v.isFree = false;
                    v.PersonID = LoggedIn.username;
                }

                try
                {
                    vse.SaveChanges();
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e);
                }
            }
            return canWork;

        }
示例#3
0
        public ActionResult CreateJob(PeopleJobvm pjvm)
        {

            if (ModelState.IsValid)
            {
            Vaktir vakt = new Vaktir();
            vakt.Date = pjvm.job.Date;
            vakt.End = pjvm.job.End;
            vakt.Start = pjvm.job.Start;
            vakt.Type = pjvm.job.Type;
            vakt.PersonID = pjvm.job.PersonID;

            string id = pjvm.job.PersonID;
            vakt.Type = pjvm.job.Type;
            Person vaktPerson = new Person();

            vaktPerson = dbm.allPeoples.Find(x => x.PersonID.Equals(id));
            vakt.Person = vaktPerson;
            dbm.addJob(vakt);

                String output = "Vakt no: " + vakt.VaktID + " has been added to database";
                TempData["Success"] = output;

            return RedirectToAction("Jobs");
        }

            pjvm.ListOfPersons = dbm.allPeoples;
            return View(pjvm);
        }
示例#4
0
        public ActionResult EditJob(PeopleJobvm viewModel)
        {
            if (ModelState.IsValid)
            {
            Vaktir v = new Vaktir();
            v.VaktID = viewModel.id;
            v.isFree = viewModel.job.isFree;
            v.Date = viewModel.job.Date;
                v.Start = viewModel.job.Start;
            v.End = viewModel.job.End;
            v.Type = viewModel.job.Type;
            v.PersonID = viewModel.job.PersonID;
            v.Person = dbm.getPerson(viewModel.job.PersonID);

            dbm.updateJob(v);

                String output = "vakt no"+ v.VaktID+ " has been updated";
                TempData["Success"] = output;

            return RedirectToAction("Jobs");
        }

            viewModel.ListOfPersons = dbm.allPeoples;
            return View(viewModel);
        }
示例#5
0
 public void addJob(Vaktir vakt)
 {
     vse.Vaktir.Add(vakt);
     vse.SaveChanges();
 }
示例#6
0
 public bool deleteJob(Vaktir dVakt)
 {
     Vaktir tmpVakt = vse.Vaktir.Find(dVakt.VaktID);
     if(tmpVakt != null)
     { 
         vse.Vaktir.Remove(dVakt);
         vse.SaveChanges();
         return true;
     }
     else 
     {
         return false;
     }
 }
示例#7
0
        public void updateJob(Vaktir v)
        {
            if(v != null)
            {
                vse.Vaktir.Find(v.VaktID).Date = v.Date;
                vse.Vaktir.Find(v.VaktID).End = v.End;
                vse.Vaktir.Find(v.VaktID).isFree = v.isFree;
                vse.Vaktir.Find(v.VaktID).Person = v.Person;
                vse.Vaktir.Find(v.VaktID).PersonID = v.PersonID;
                vse.Vaktir.Find(v.VaktID).Start = v.Start;
                vse.Vaktir.Find(v.VaktID).Type = v.Type;

                vse.SaveChanges();

            }
        }