Beispiel #1
0
        public ActionResult GetPrisonerDetails(int id)
        {
            Prisoner prisoner = (from item in db.Prisoners
                                 where item.prisonerID == id
                                 select item).FirstOrDefault();


            prisonerSatyIn cell = (from item in db.prisonerSatyIns
                                   where item.prisonerid == id
                                   select item).FirstOrDefault();

            PrisonerWorkA work = (from item in db.PrisonerWorkAs
                                  where item.prisonerid == id
                                  select item).FirstOrDefault();

            prisonerDetails prisonerDetails = new prisonerDetails();

            prisonerDetails.prisoner = prisoner;

            if (cell != null)
            {
                prisonerDetails.cell = cell.prisonerCell;
            }

            if (work != null)
            {
                prisonerDetails.job = work.Job;
            }


            return(View(prisonerDetails));
        }
Beispiel #2
0
        public ActionResult AssignAjobPost(int id)
        {
            var job = (from item in db.Jobs
                       where item.jobID == id
                       select item).FirstOrDefault();
            int prisonerID = Convert.ToInt32(Session["prisonerID"]);

            var prisoner = (from item in db.Prisoners
                            where item.prisonerID == prisonerID
                            select item).FirstOrDefault();

            var query = (from item in db.PrisonerWorkAs
                         where item.prisonerid == prisoner.prisonerID
                         select item).FirstOrDefault();

            //updating the job
            if (query != null)
            {
                query.Prisoner   = prisoner;
                query.Job        = job;
                query.jobid      = job.jobID;
                query.prisonerid = prisoner.prisonerID;
                query.since      = DateTime.Now.Date;

                db.Entry(query).State = EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                //creating new job-prisoner relation
                PrisonerWorkA relation = new PrisonerWorkA();

                relation.Prisoner   = prisoner;
                relation.Job        = job;
                relation.jobid      = job.jobID;
                relation.prisonerid = prisoner.prisonerID;
                relation.since      = DateTime.Now.Date;

                db.Entry(relation).State = EntityState.Added;
                db.SaveChanges();

                job.availablePositionsCount--;
                db.Entry(job).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(Redirect("~/Prisoners/GetPrisonersData"));
        }