public IActionResult AddAccountForEmployee(string emp_id, string account_name, string account_password) { NhanVien tmp = new NhanVien(); tmp.MaNhanVien = int.Parse(emp_id); NhanVien editNv = db.NhanVien.Find(tmp.MaNhanVien); TaiKhoanViewModel query_account = new TaiKhoanViewModel(db); TaiKhoan newAcc = new TaiKhoan { TenTaiKhoan = account_name, MatKhau = account_password, MaPhanQuyen = "nv", Email = editNv.Email, AnhDaiDien = editNv.HinhAnh }; query_account.InsertTaiKhoan(newAcc); editNv.MaTaiKhoan = newAcc.MaTaiKhoan;//get last inserted id NhanVienViewModel query_employee = new NhanVienViewModel(db); query_employee.EditNhanVien(editNv); var response = query_employee.GetNhanVienById(emp_id); return(Json(response)); }
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)); }