Ejemplo n.º 1
0
        // POST: /Manage/CreateJob
        public ActionResult AddJobToUser(AddJobToUserViewModel model)
        {
            AddJobToUserVMValidator validator = new AddJobToUserVMValidator();
            ValidationResult result = validator.Validate(model);

            //Traitement
            var db = new ApplicationDbContext();
            if (result.IsValid)
            {
                var PeriodsDb = db.Periods;

                var period = new Period { En_Cours = false, debut = model.Debut, fin = model.Fin, CompanyId = model.SelectedCompany, JobId = model.SelectedJob, UserId = model.SelectedUser };

                PeriodsDb.Add(period);
                db.SaveChanges();

                return RedirectToAction("List", "Account");
            }

            foreach (ValidationFailure failer in result.Errors)
            {
                ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage);
            }
            //Redirection vers la liste des périodes pour l'utilisateur concerné
            model.Jobs = db.Jobs.ToList();
            model.Users = db.Users.ToList();
            model.Companies = db.Companies.ToList();
            return View(model);
        }
Ejemplo n.º 2
0
 // GET: /Manage/AddJobToUser (creates a period)
 public ActionResult AddJobToUser()
 {
     var db = new ApplicationDbContext();
     var vm = new AddJobToUserViewModel()
     {
         Jobs = db.Jobs.ToList(),
         Users = db.Users.ToList(),
         Companies = db.Companies.ToList(),
     };
     return View(vm);
 }