Example #1
0
        public IActionResult Edit([FromForm] VmCustomer viewModel)
        {
            base._logger.Debug($"Post edit! {viewModel.Name}({viewModel.Id})");


            ViewBag.Title = "Customer - Create";

            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Model validation fail";
                return(RedirectToAction("Index", controllerName: "CustomerMvc"));
            }

            using (var custService = new CustomerService(DbContextFactory.Create()))
            {
                var entity = custService.Get(x => x.Id.Equals(viewModel.Id)).FirstOrDefault();
                if (entity != null)
                {
                    entity.Name        = viewModel.Name;
                    entity.Phone       = viewModel.Phone;
                    entity.Description = viewModel.Description;
                    custService.Update(entity);
                }
                else
                {
                    throw new Exception($"The customer (id: {viewModel.Id}) is not exist!");
                }
            }

            return(RedirectToAction("Index", controllerName: "CustomerMvc"));
        }
Example #2
0
        public IActionResult Create()
        {
            ViewBag.Title = "Customer - Create";
            var viewModel = new VmCustomer();

            return(View(viewModel));
        }
Example #3
0
        public ActionResult QueryCreateView()
        {
            var viewModel = new VmCustomer();

            return(PartialView("~/Areas/Basic/Views/CustomerMvc/_CreateView.cshtml", viewModel));
            //return PartialView("~/Areas/Basic/Views/CustomerMvc/_CreateViewTh.cshtml", viewModel); //Use Tag helper page
        }
Example #4
0
        public IActionResult Create([FromForm] VmCustomer viewModel)
        {
            ViewBag.Title = "Customer - Create";

            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Model validation fail";
                return(RedirectToAction("Index", controllerName: "CustomerMvc"));
            }

            using (var custService = new CustomerService(DbContextFactory.Create()))
            {
                var entity = DaoFactory.Create <VmCustomer, Angular2.Mvc.DAL.Models.DAO.Customer>(viewModel);
                custService.Add(entity);
            }
            return(RedirectToAction("Index", controllerName: "CustomerMvc"));
        }