Esempio n. 1
0
        public async Task <IActionResult> Create(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var worker = await _userManager.FindByIdAsync(id);

            VacationVM v = new VacationVM();

            v.WorkerId      = worker.Id;
            v.WorkerAccount = worker.Account;
            return(View(v));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(string id, VacationVM vacationVM)
        {
            var worker = await _userManager.FindByIdAsync(id);

            if (!ModelState.IsValid)
            {
                vacationVM.WorkerAccount = worker.Account;
                vacationVM.WorkerId      = worker.Id;
                return(View(vacationVM));
            }

            Vacation vacation = new Vacation();

            vacation.WorkerId  = worker.Id;
            vacation.StartDate = vacationVM.StartDate;
            vacation.EndDate   = vacationVM.EndDate;

            await _context.Vacations.AddAsync(vacation);

            await _context.SaveChangesAsync();

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