コード例 #1
0
        public ActionResult Edit(ProjectCreateOrUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                ProjectService.Update(model.Id, model.Name, model.IsFixed, model.IsDeactivated, model.Price, model.StartDate, model.EndDate);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }

            return(RedirectToAction("Index", "Project"));
        }
コード例 #2
0
        public ActionResult Create(ProjectCreateOrUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                //model.Customers = new SelectList(CustomerService.All(), "Id", "Name");
                return(View(model));
            }

            try
            {
                ProjectService.Create(model.Name, model.IsFixed, model.Price, model.StartDate, model.EndDate, model.CustomerId);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);

                return(View(model));
            }

            return(RedirectToAction("Index", "Project"));
        }
コード例 #3
0
        public ActionResult Create(Guid?id)
        {
            List <Customer> allCustomers = CustomerService.All().ToList();

            ProjectCreateOrUpdateModel model = new ProjectCreateOrUpdateModel();

            model.Customers = new SelectList(allCustomers, "Id", "Name");

            if (id.HasValue)
            {
                Customer matchingCustomer = allCustomers.FirstOrDefault(x => x.Id.Equals(id.Value));
                if (id.Value == Guid.Empty || matchingCustomer == null)
                {
                    return(RedirectToAction("Create", "Project", new { @id = (Guid?)null }));
                }

                model.CustomerId       = matchingCustomer.Id;
                model.MatchingCustomer = matchingCustomer;
            }

            return(View(model));
        }
コード例 #4
0
        public ActionResult Edit(Guid id)
        {
            try
            {
                Project data = ProjectService.Get(id);

                ProjectCreateOrUpdateModel viewModel = new ProjectCreateOrUpdateModel();
                viewModel.Id            = data.Id;
                viewModel.Name          = data.Name;
                viewModel.Price         = data.Price;
                viewModel.IsFixed       = data.IsFixed;
                viewModel.IsDeactivated = data.IsDeactivated;
                viewModel.StartDate     = data.StartDate;
                viewModel.EndDate       = data.EndDate;

                return(View(viewModel));
            }
            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }