Esempio n. 1
0
 public ActionResult Create([Bind(Include = "Name,Description,Deadline,SelectedCompany")] CreateJobViewModel jobVM)
 {
     if (ModelState.IsValid)
     {
         //Gör om VM till riktigt objekt
         Job j = new Job();
         j.Name = jobVM.Name;
         j.Description = jobVM.Description;
         j.Deadline = (DateTime)jobVM.Deadline;
         j.Published = DateTime.Now;
         j.CompanyId = jobVM.SelectedCompany;
         //Använd repo för att lägga till i db
         repo.CreateJob(j);
         //Återvänd
         return RedirectToAction("Index");
     }
     return View(jobVM);
 }
        // EDIT SPECIFIC JOB
        public Job EditJob(Job job)
        {
            db.Entry(job).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return job;
        }
        // DELETE JOB
        public Job DeleteJob(Job job)
        {
            db.Jobs.Remove(job);
            db.SaveChanges();

            return job;
        }
 // CREATE NEW JOB AND ADD TO DATABASE
 public Job CreateJob(Job job)
 {
     db.Jobs.Add(job);
     db.SaveChanges();
     return job;
 }