Ejemplo n.º 1
0
        public IActionResult AddOrEdit(int id = 0)
        {
            MemberAddOrEditViewModel viewModel = null;

            //Create
            if (id == 0)
            {
                viewModel = new MemberAddOrEditViewModel();
            }
            //Edit
            else
            {
                var member = _context.Member.Find(id);
                viewModel = _mapper.Map <MemberAddOrEditViewModel>(member);
            }

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public IActionResult AddOrEdit(MemberAddOrEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var member = _mapper.Map <Member>(viewModel);

                //Create
                if (viewModel.Id == 0)
                {
                    _context.Add(member);
                }
                else
                {
                    _context.Update(member);
                }

                _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(viewModel));
        }