コード例 #1
0
        public ActionResult Add(IFormCollection collection)
        {
            try
            {
                var customerID = System.Convert.ToInt32(collection["customer"]);
                var serviceID  = System.Convert.ToInt32(collection["service"]);

                _context.Add(new ServiceContract(customerID, serviceID));
                _context.SaveChanges();

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Add(IFormCollection collection)
        {
            try
            {
                var c = new Customer {
                    Name = collection["Name"]
                };
                TryValidateModel(c);

                _context.Add(c);
                _context.SaveChanges();

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
        public ActionResult Add(IFormCollection collection)
        {
            try
            {
                var s = new Service
                {
                    Name = collection["Name"],
                    Cost = System.Convert.ToInt32(collection["Cost"])
                };
                TryValidateModel(s);

                _context.Add(s);
                _context.SaveChanges();

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(View());
            }
        }