public IActionResult EditProfile(IFormFile img, string email, string id, string old_img) { TaiKhoan tmp = db.TaiKhoan.SingleOrDefault(x => x.MaTaiKhoan == int.Parse(id)); TaiKhoan editTk = new TaiKhoan { MaPhanQuyen = "kh", MaTaiKhoan = int.Parse(id), Email = email, TenTaiKhoan = tmp.TenTaiKhoan, MatKhau = tmp.MatKhau }; if (img != null) { string path_to_image = "wwwroot/uploads/employee/" + img.FileName; using (var stream = new FileStream(path_to_image, FileMode.Create)) { img.CopyTo(stream); } editTk.AnhDaiDien = img.FileName; } else { editTk.AnhDaiDien = old_img; } TaiKhoanViewModel query = new TaiKhoanViewModel(db); query.EditTaiKhoan(editTk); return(RedirectToAction("Index")); }
public IActionResult UpdateEmployee(IFormFile emp_img, string emp_name, string emp_identity, string emp_email, string emp_position, string emp_salary, string emp_info, string old_emp_img, string emp_id, string acc_id) { NhanVien editEmployee = new NhanVien { MaNhanVien = int.Parse(emp_id), HoTen = emp_name, MaChucVu = int.Parse(emp_position), Luong = float.Parse(emp_salary), Email = emp_email, MoTa = emp_info, Cmnd = emp_identity }; if (acc_id == "0") { editEmployee.MaTaiKhoan = null; } else { editEmployee.MaTaiKhoan = int.Parse(acc_id); } if (emp_img == null) { editEmployee.HinhAnh = old_emp_img; } else { string path_to_image = "wwwroot/uploads/employee/" + emp_img.FileName; using (var stream = new FileStream(path_to_image, FileMode.Create)) { emp_img.CopyTo(stream); } editEmployee.HinhAnh = emp_img.FileName; } NhanVien tmp = db.NhanVien.SingleOrDefault(x => x.MaNhanVien == int.Parse(emp_id)); editEmployee.NgayBatDau = tmp.NgayBatDau; NhanVienViewModel query = new NhanVienViewModel(db); query.EditNhanVien(editEmployee); if (editEmployee.MaTaiKhoan != null) { TaiKhoan thisTaiKhoan = db.TaiKhoan.Where(x => x.MaTaiKhoan == editEmployee.MaTaiKhoan).SingleOrDefault(); thisTaiKhoan.AnhDaiDien = editEmployee.HinhAnh; thisTaiKhoan.Email = editEmployee.Email; TaiKhoanViewModel query_tk = new TaiKhoanViewModel(db); query_tk.EditTaiKhoan(thisTaiKhoan); } var response = query.GetDsNhanVien(); return(Json(response)); }