Exemplo n.º 1
0
        public IActionResult Worktime(AddTimeViewModel addTimeViewModel)
        {
            if (ModelState.IsValid)
            {
                Project newProject = context.Projects.Single(p => p.ProjectID == addTimeViewModel.ProjectID);

                Worktime newWorktime = new Worktime
                {
                    Hours       = addTimeViewModel.Hours,
                    WeekRange   = WeekNumber.WeekDict[addTimeViewModel.WeekId],
                    Description = addTimeViewModel.Description,
                    Project     = newProject
                };

                newWorktime.Amount     = newWorktime.Hours * (double)newWorktime.Project.Rate;
                newWorktime.OpenStatus = true;

                context.Worktimes.Add(newWorktime);
                context.SaveChanges();

                return(Redirect("/?id=" + addTimeViewModel.ProjectID));
            }

            addTimeViewModel.SelectProjects = SelectListGen.SelectProjects(context.Projects.ToList());

            return(View("AddTime", addTimeViewModel));
        }
Exemplo n.º 2
0
        //Go to Add Time form
        public IActionResult AddTime()
        {
            AddTimeViewModel addTimeViewModel = new AddTimeViewModel();

            //Generate list of projects
            addTimeViewModel.SelectProjects = SelectListGen.SelectProjects(context.Projects.ToList());

            return(View(addTimeViewModel));
        }