コード例 #1
0
ファイル: CarriersController.cs プロジェクト: luizgava/axado
        public ActionResult Create(CarrierViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var carrier = new Carrier
                {
                    Name = viewModel.Name,
                    Adress = viewModel.Adress,
                    City = viewModel.City,
                    Country = viewModel.Country,
                    Identification = viewModel.Identification,
                    PhoneNumber = viewModel.PhoneNumber,
                    State = viewModel.State,
                    Url = viewModel.Url
                };
                var context = new Context();
                carrier.Create();
                context.Carriers.Add(carrier);
                context.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(viewModel);
        }
コード例 #2
0
ファイル: CarriersController.cs プロジェクト: luizgava/axado
        public ActionResult Edit(CarrierViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var context = new Context();
                var carrier = context.Carriers.First(x => x.Id == viewModel.Id);
                carrier.Name = viewModel.Name;
                carrier.Adress = viewModel.Adress;
                carrier.City = viewModel.City;
                carrier.Country = viewModel.Country;
                carrier.Identification = viewModel.Identification;
                carrier.PhoneNumber = viewModel.PhoneNumber;
                carrier.State = viewModel.State;
                carrier.Url = viewModel.Url;
                carrier.Update();
                context.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(viewModel);
        }