Exemplo n.º 1
0
        public ActionResult Save(Client Client)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new UserPlanViewModel
                {
                    Plans  = _context.Plan.ToList(),
                    Client = Client
                };
                ViewBag.Acao = "Novo Usuário";

                return(View("ClientForm", viewModel));
            }

            if (Client.Id == 0)
            {
                Client.SubscribeDate = DateTime.Now;
                _context.Client.Add(Client);
            }
            else
            {
                var clientInDb = _context.Client.Single(s => s.Id == Client.Id);

                clientInDb.Mail               = Client.Mail;
                clientInDb.Name               = Client.Name;
                clientInDb.PlanId             = Client.PlanId;
                clientInDb.SubscribeDate      = Client.SubscribeDate;
                clientInDb.IsSubscribedToNews = Client.IsSubscribedToNews;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Client"));
        }
        public ActionResult Index()
        {
            Client usuario = new Client()
            {
                Id   = 1,
                Name = "Thiago"
            };

            //var lstPlanos = new List<Plan>()
            //{
            //    new Models.Plan() {Id=1, Name="Plano 1", Value = 100 },
            //    new Models.Plan() {Id=2, Name="Plano 2", Value = 200 }
            //};

            if (HttpContext.Cache["Planos"] == null)
            {
                HttpContext.Cache["Planos"] = _context.Plan.ToList();
            }

            var lstPlanos = (List <Plan>)HttpContext.Cache["Planos"];

            //HttpContext.Cache.Remove("Planos");

            UserPlanViewModel model = new UserPlanViewModel();

            model.Client = usuario;
            model.Plans  = lstPlanos;


            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult New()
        {
            List <Plan> plans = new List <Plan>();

            plans = _context.Plan.ToList();

            UserPlanViewModel viewModel = new UserPlanViewModel
            {
                Client = new Client(),
                Plans  = plans
            };

            ViewBag.Acao = "Novo Usuário";

            return(View("ClientForm", viewModel));
        }
Exemplo n.º 4
0
        public ActionResult Edit(int id)
        {
            var client = _context.Client.Find(id);

            if (client == null)
            {
                return(HttpNotFound());
            }

            List <Plan> plans = new List <Plan>();

            plans = _context.Plan.ToList();

            var viewModel = new UserPlanViewModel
            {
                Plans  = plans,
                Client = client
            };

            ViewBag.Acao = "Editar Usuário";
            return(View("ClientForm", viewModel));
        }