コード例 #1
0
        public async Task <IActionResult> Edit(string id, [Bind("Iddichvu,Tendv,Trangthai")] DichvuViewModel dichvu)
        {
            if (id != dichvu.Iddichvu)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Dichvu d = await _dichvuRepository.GetByIdAsync(dichvu.Iddichvu);

                    d.Iddichvu  = dichvu.Iddichvu;
                    d.Tendv     = dichvu.Tendv;
                    d.Trangthai = dichvu.Trangthai;
                    var result = _dichvuRepository.Update(d);
                    if (result == null)
                    {
                        SetAlert("Cập nhật dịch vụ không thành công", "error");
                    }
                    else
                    {
                        SetAlert("Cập nhật dịch vụ thành công", "success");
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(dichvu));
        }
コード例 #2
0
        // GET: Dichvu/Edit/5
        public async Task <IActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Dichvu dichvu = await _dichvuRepository.GetByIdAsync(id);

            if (dichvu == null)
            {
                return(NotFound());
            }
            DichvuViewModel dichvuViewModel = new DichvuViewModel
            {
                Iddichvu  = dichvu.Iddichvu,
                Tendv     = dichvu.Tendv,
                Trangthai = dichvu.Trangthai
            };

            Trangthai(dichvuViewModel.Trangthai);
            return(View(dichvuViewModel));
        }