public ActionResult Create(CreateWorkDone workDone)
        {
            WorkDoneRepository workDoneRepo = new WorkDoneRepository();

            // Get DropDownList values
            ClientRepository   clientRepo   = new ClientRepository();
            Client             client       = clientRepo.GetById(workDone.ClientId);
            WorkTypeRepository workTypeRepo = new WorkTypeRepository();
            WorkType           workType     = workTypeRepo.GetById(workDone.WorkTypeId);

            WorkDone newWorkDone = new WorkDone(0, client, workType, DateTimeOffset.Now);

            // If it's good, submit and go back to Index.
            if (ModelState.IsValid)
            {
                workDoneRepo.Insert(newWorkDone);
                return(RedirectToAction("Index"));
            }

            // If it's not good, repost the page with errors.
            return(View("Create", workDone));
        }
Beispiel #2
0
        public ActionResult Create(CreateWorkDone formModel)
        {
            var workDone = new WorkDone()
            {
                ClientId   = formModel.ClientId,
                WorkTypeId = formModel.WorkTypeId,
                StartedOn  = formModel.StartedOn,
                EndedOn    = formModel.EndedOn
            };

            try
            {
                var workDoneRepo = new WorkDoneRepository(_context);
                workDoneRepo.Insert(workDone);
                return(RedirectToAction("Index"));
            }
            catch
            {
                // TODO handle this
                ModelState.AddModelError("Create", "Unable to add new work done");
                return(View(formModel));
            }
        }