public ActionResult Create() { try { using (var db = new KhaoThiDBContext()) { if (db.Roles.Count() == 0) { var role = new Role(); role.RoleID = "Admin"; role.RoleName = "Admin"; db.Roles.Add(role); db.SaveChanges(); var role2 = new Role(); role2.RoleID = "Lecture"; role2.RoleName = "Giảng viên"; db.Roles.Add(role2); db.SaveChanges(); } if (db.Accounts.Count() == 0) { var acc = new Account(); acc.UserName = "******"; acc.Password = strPro.GetMD5("123456"); acc.ConfirmPassword = acc.Password; acc.RoleID = "Admin"; db.Accounts.Add(acc); db.SaveChanges(); } } } catch {} return(RedirectToAction("Login", "Account")); }
public ActionResult Create([Bind(Include = "RoleID,RoleName")] Role role) { if (ModelState.IsValid) { db.Roles.Add(role); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(role)); }
public ActionResult Create([Bind(Include = "IdKyThi,MaKyThi,TenKyThi,NgayTao,NguoiTao,ChuThich,isDelete,Status")] KyThi kyThi) { kyThi.NgayTao = DateTime.Now; kyThi.isDelete = false; kyThi.Status = true; kyThi.NguoiTao = Session["idUser"].ToString(); if (ModelState.IsValid) { db.KyThis.Add(kyThi); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(kyThi)); }
public ActionResult Create([Bind(Include = "UserName,Password,RoleID,ConfirmPassword")] Account account) { try { if (ModelState.IsValid) { var md5Pass = strPro.GetMD5(account.Password); account.Password = md5Pass; account.ConfirmPassword = md5Pass; db.Accounts.Add(account); db.SaveChanges(); return(RedirectToAction("Index")); } } catch { ModelState.AddModelError("", "Username is exist. Please try again."); ViewBag.ListRole = db.Roles.ToList(); } return(View(account)); }
public ActionResult OverwriteData(HttpPostedFileBase file, int?idKyThi) { // delete data from Danh sach thi db.DanhSachThis.RemoveRange(db.DanhSachThis.Where(m => m.IdKyThi == idKyThi)); db.SaveChanges(); // delete data from Danh sach phach db.DanhSachPhachs.RemoveRange(db.DanhSachPhachs.Where(m => m.IdKyThi == idKyThi)); db.SaveChanges(); try { if (file.ContentLength > 0) { CopyDataFormExcel(file, idKyThi); InsertDataMonHoc(idKyThi); } return(RedirectToAction("Index", "DanhSachThi_Ad", new { id = idKyThi })); } catch { return(View("UpLoadFail")); } }
public ActionResult ResetPass() { try { using (var db = new KhaoThiDBContext()) { var account = db.Accounts.Find("Admin"); account.Password = strPro.GetMD5("123456"); account.ConfirmPassword = account.Password; db.SaveChanges(); } } catch { } return(RedirectToAction("Index", "Home_Ad")); }
private void InsertDataMonHoc(int?id) { var db = new KhaoThiDBContext(); var model = db.DanhSachThis.Where(m => m.IdKyThi == id).Select(m => new { m.f_mamh, m.phongthi, m.ngaythi, m.tietbatdau, m.sotiet, m.IdKyThi, m.f_tenmhvn }).Distinct().ToList(); for (int i = 0; i < model.Count; i++) { DanhSachThi dst = new DanhSachThi(); dst.f_tenmhvn = model[i].f_tenmhvn; dst.f_masv = model[i].f_mamh; dst.f_holotvn = model[i].phongthi; dst.ngaythi = model[i].ngaythi; dst.tietbatdau = model[i].tietbatdau; dst.sotiet = model[i].sotiet; dst.IdKyThi = model[i].IdKyThi; dst.sobaodanh = 0; db.DanhSachThis.Add(dst); } db.SaveChanges(); }