Ejemplo n.º 1
0
        public Permuta Save(PermutaEditVM vm)
        {
            Permuta model;

            if (vm.Id == 0)
            {
                model = vm.ConvertTo <Permuta>();
                model.FuncionarioId = _funcionarioProvider.User.Id;
                Data.Add(model);
            }
            else
            {
                model = Get(vm.Id);
                _context.Set <PermutaRegiaoUnidade>().RemoveRange(model.Regioes);
                _context.Set <PermutaTipoUnidade>().RemoveRange(model.TiposUnidade);

                model.Inject(vm);
            }

            model.Regioes = vm.Regioes.Select(a => new PermutaRegiaoUnidade
            {
                RegiaoUnidadeId = a
            }).ToList();

            model.TiposUnidade = vm.TiposUnidade.Select(a => new PermutaTipoUnidade
            {
                TipoUnidadeId = a
            }).ToList();

            _context.SaveChanges();
            NotifyUser(model);
            return(model);
        }
Ejemplo n.º 2
0
        public ActionResult Post(PermutaEditVM vm)
        {
            if (ModelState.IsValid)
            {
                _domain.Save(vm);
                this.AlertSuccess();
                return(RedirectToAction("Index"));
            }

            this.AlertError();
            ViewBag.TipoOptions   = _tipoUnidadeDomain.ToOptions();
            ViewBag.RegiaoOptions = _regiaoUnidadeDomain.ToOptions();
            return(View("Self", vm));
        }