Пример #1
0
        public async Task <IActionResult> Add(int id)
        {
            var lk = await _lkRepo.getById(id);

            if (lk == null)
            {
                return(View("~/Views/Error/404.cshtml"));
            }

            DonGiaDTO gia   = new DonGiaDTO();
            var       lkDTO = _mapper.Map <LinhKienDTO>(lk);

            gia.LinhKien = lkDTO;
            return(View("~/Views/Admin/Gia/Add.cshtml", gia));
        }
Пример #2
0
        public async Task <IActionResult> AddPost(int id, [FromForm] DonGiaDTO dto)
        {
            var lk = await _lkRepo.getById(id);

            ViewBag.TenLK = lk.TenLK;

            if (!ModelState.IsValid)
            {
                return(View("~/Views/Admin/Gia/Add.cshtml", dto));
            }


            var gia = _mapper.Map <DonGia>(dto);

            gia.LinhKien = lk;
            gia.ApDung   = false;

            await _giaRepo.Add(gia);

            return(Redirect(Url.Action("Index", "Gia", new { id = id })));
        }