Exemple #1
0
        public async Task <IActionResult> Edit(int id, BranchFormViewModel branchVM)
        {
            if (id != branchVM.Id)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var branch = _mapper.Map <Branch>(branchVM);

                    _context.Update(branch);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await BranchExists(branchVM.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            branchVM.Entities = _context.Entities.ToList();

            return(View(branchVM));
        }
        public ActionResult New()
        {
            var viewModel = new BranchFormViewModel
            {
                Branch = new Branch()
            };

            return(View("BranchForm", viewModel));
        }
Exemple #3
0
        // GET: Branches/Create
        public IActionResult Create()
        {
            var branchVM = new BranchFormViewModel
            {
                Entities = _context.Entities.ToList()
            };

            return(View(branchVM));
        }
        public ActionResult NewBranch()
        {
            var houses    = _houseRepository.GetAll().ToList();
            var viewModel = new BranchFormViewModel
            {
                Branch = new Branch(),
                Houses = houses
            };

            return(View("BranchForm", viewModel));
        }
Exemple #5
0
        public async Task <IActionResult> Create(BranchFormViewModel branchVM)
        {
            if (ModelState.IsValid)
            {
                var branch = _mapper.Map <Branch>(branchVM);

                _context.Add(branch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            branchVM.Entities = _context.Entities.ToList();

            return(View(branchVM));
        }
        public ActionResult Edit(int id)
        {
            var branch = _context.Branches.SingleOrDefault(b => b.Id == id);

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

            var viewModel = new BranchFormViewModel
            {
                Branch = branch
            };

            return(View("BranchForm", viewModel));
        }
        public ActionResult Edit(int id)
        {
            var    allBranches = _branchRepository.GetAll().ToList();
            var    viewModel   = new BranchFormViewModel();
            Branch b           = allBranches.SingleOrDefault(v => v.Id == id);

            if (b == null)
            {
                return(HttpNotFound());
            }
            else
            {
                viewModel.Branch = b;
                viewModel.Houses = _houseRepository.GetAll().ToList();
            }

            return(View("BranchForm", viewModel));
        }
        public ActionResult Save(Branch branch)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new BranchFormViewModel
                {
                    Branch = branch,
                    Houses = _houseRepository.GetAll().ToList()
                };
                return(View("BranchForm", viewModel));
            }

            if (branch.Id == 0)
            {
                _branchRepository.Create(branch);
            }
            else
            {
                _branchRepository.Update(branch);
            }
            return(RedirectToAction("Index", "Branch"));
        }