Exemple #1
0
        public ActionResult Create(CreateWorkDone model)
        {
            try
            {
                Client   client   = new ClientRepo(context).GetById(model.ClientId);
                WorkType workType = new WorkTypeRepo(context).GetById(model.WorkTypeId);

                // Create an instance of the work done with the client and work
                // type
                WorkDone workDone = new WorkDone(0, client, workType);

                var wRepo = new WorkDoneRepo(context);
                wRepo.Insert(workDone);
                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException ex)
            {
                HandleDbUpdateException(ex);
            }

            // Create a view model
            CreateWorkDone viewModel = new CreateWorkDone();

            viewModel.PopulateSelectLists(context);

            viewModel.ClientId   = model.ClientId;
            viewModel.WorkTypeId = model.WorkTypeId;
            return(View("Create", viewModel));
        }
Exemple #2
0
        public ActionResult Create(CreateWorkDone model)
        {
            try
            {
                // Get the client and work type based on values submitted from
                // the form
                Client   client   = new ClientRepository(context).GetById(model.ClientId);
                WorkType workType = new WorkTypeRepository(context).GetById(model.WorkTypeId);

                // Create an instance of the work done with the client and work
                // type
                WorkDone workDone = new WorkDone(client, workType);  /////////
                new WorkDoneRepository(context).Insert(workDone);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
            }

            // Create a view model
            CreateWorkDoneView viewModel = new CreateWorkDoneView();

            // Copy over the values from the values submitted
            viewModel.ClientId   = model.ClientId;
            viewModel.StartedOn  = model.StartedOn;
            viewModel.WorkTypeId = model.WorkTypeId;

            // Go get the value for the drop-downs, again.
            viewModel.Clients   = new ClientRepository(context).GetClients();
            viewModel.WorkTypes = new WorkTypeRepository(context).GetWorkTypes();
            return(View("Create", viewModel));
        }
Exemple #3
0
        public ActionResult Create()
        {
            CreateWorkDone model = new CreateWorkDone();

            model.PopulateSelectLists(context);

            return(View("Create", model));
        }
        public ActionResult Create()
        {
            // Populate DropDownLists
            ClientRepository   clientRepo   = new ClientRepository();
            List <Client>      clients      = clientRepo.GetClients();
            WorkTypeRepository workTypeRepo = new WorkTypeRepository();
            List <WorkType>    workTypes    = workTypeRepo.GetWorkTypes();

            // Bind model
            CreateWorkDone workDone = new CreateWorkDone(clients, workTypes);

            return(View("Create", workDone));
        }
Exemple #5
0
        public ActionResult Create()
        {
            var clientRepo    = new ClientRepository(_context);
            var clientItems   = clientRepo.GetSelectListItems();
            var workTypeRepo  = new WorkTypeRepository(_context);
            var workTypeItems = workTypeRepo.GetSelectListItems();
            var formModel     = new CreateWorkDone
            {
                ClientItems   = clientItems,
                WorkTypeItems = workTypeItems
            };

            return(View(formModel));
        }
        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));
        }
Exemple #7
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));
            }
        }