public async Task <ActionResult> Edit(int id, NhanVienViewModel nhanVien, HttpPostedFileBase avatar) { if (avatar != null && avatar.ContentLength > 0) { try { string path = Path.Combine(Server.MapPath("~/Content/image/user"), Path.GetFileName(avatar.FileName)); avatar.SaveAs(path); nhanVien.avatar = avatar.FileName; } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } else { // nhanVien.avatar = "default.png"; nhanVien.avatar = nhanVien.checkImage; } if (id == 1) { nhanVien.trangThai = true; nhanVien.maChucVu = 3; } //Get nhân viên muốn update (find by ID) NhanVien edit = (NhanVien)await _nhanVienKhoBus.Find(id); if (edit == null) { return(HttpNotFound()); } else { // Access Update from Business try { await _nhanVienKhoBus.Update(nhanVien, edit); SetAlert("Đã cập nhật nhân viên thành công!!!", "success"); } catch { TempData["nhanVien"] = nhanVien; SetAlert("Đã xảy ra lỗi! Bạn hãy cập nhật lại", "error"); } } return(RedirectToAction("Index")); }