public ActionResult Login(FormCollection fc) { string username = fc["username"]; string password = fc["password"]; string encrptPwd = Md5(password); bool RememberMe = fc["RememberMe"] == null ? false : true; string returnUrl = Convert.ToString(TempData["ReturnUrl"]); UnityOfWork unity = new UnityOfWork(); SysUser user = unity.SysUserRepository.Get(t => t.UserName == username && t.PassWord == password).FirstOrDefault(); unity.Dispose(); if (user != null) { FormsAuthentication.SetAuthCookie(user.UserName, RememberMe); if (returnUrl != null) { return(Redirect(returnUrl)); } else { return(Redirect("~/")); } } return(View()); }
public static bool AddProject(string id, string descripton, string deadline) { var ParsedDeadLine = new DateTime(); try { ParsedDeadLine = DateTime.Parse(deadline); } catch (Exception) { return(false); } var unit = new UnityOfWork(new ProjectTracerEntities()); unit.Project.Add(new Project() { Project_ID = id, Description = descripton, DeadLine = ParsedDeadLine, Result = "notregistered", }); try { unit.Complete(); unit.Dispose(); return(true); } catch (Exception e) { return(false); } }
//// POST: Products/Create //// To protect from overposting attacks, enable the specific properties you want to bind to, for //// more details see https://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Create([Bind(Include = "Id,Name,Slug,Description,Price,ImageUrl")] Product product) //{ // if (ModelState.IsValid) // { // db.Products.Add(product); // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(product); //} //// GET: Products/Edit/5 //public ActionResult Edit(int? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // Product product = db.Products.Find(id); // if (product == null) // { // return HttpNotFound(); // } // return View(product); //} //// POST: Products/Edit/5 //// To protect from overposting attacks, enable the specific properties you want to bind to, for //// more details see https://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Edit([Bind(Include = "Id,Name,Slug,Description,Price,ImageUrl")] Product product) //{ // if (ModelState.IsValid) // { // db.Entry(product).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); // } // return View(product); //} //// GET: Products/Delete/5 //public ActionResult Delete(int? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // Product product = db.Products.Find(id); // if (product == null) // { // return HttpNotFound(); // } // return View(product); //} //// POST: Products/Delete/5 //[HttpPost, ActionName("Delete")] //[ValidateAntiForgeryToken] //public ActionResult DeleteConfirmed(int id) //{ // Product product = db.Products.Find(id); // db.Products.Remove(product); // db.SaveChanges(); // return RedirectToAction("Index"); //} protected override void Dispose(bool disposing) { if (disposing) { unityOfWork.Dispose(); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { uofw.Dispose(); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { _unit.Dispose(); base.Dispose(disposing); }
// GET: User public ActionResult Index() { //分布式事务 //using (var db = new DAL.AccountContext()) //{ // using (var ts = new TransactionScope(TransactionScopeOption.Required)) // { // //db数据库上下文操作 // ts.Complete(); // } //} //,EF在DbContext对象上提供了Database.BeginTransaction()方法,当使用上下文类在事务中执行原生SQL命令时,这个方法特别有用 //using (var db = new DAL.AccountContext()) //{ // using (var trans = db.Database.BeginTransaction()) // { // try // { // db.SysUsers.SqlQuery("select * from sysuers"); // trans.Commit(); // } // catch // { // trans.Rollback(); // } // finally // { // } // } //} //var s = unityOfWork.DbTransaction; //unityOfWork.SysUserRepository.Insert(new SysUser { CreateDate = DateTime.Now, Email = "*****@*****.**", PassWord = "******", UserName = "******", SysDepartment = new SysDepartment { DepartmentName = "消防部", DepartmentDesc = "工资结算财务审计" } }); //unityOfWork.SysUserRepository.Insert(new Models.SysUser { CreateDate = DateTime.Now, Email = "*****@*****.**", PassWord = "******", UserName = "******" }); //unityOfWork.SysUserRepository.Insert(new SysUser { CreateDate = DateTime.Now, Email = "*****@*****.**", PassWord = "******", UserName = "******", SysDepartment = new SysDepartment { DepartmentName = "研发部", DepartmentDesc = "工资结算财务审计" } }); //unityOfWork.SysUserRepository.Insert(new Models.SysUser { CreateDate = DateTime.Now, Email = "*****@*****.**", PassWord = "******", UserName = "******" }); //unityOfWork.Commit(); // unityOfWork.SysUserRepository.Insert(new SysUser { CreateDate = DateTime.Now, Email = "*****@*****.**", PassWord = "******", UserName = "******", SysDepartment = new SysDepartment { DepartmentName = "财务部", DepartmentDesc = "工资结算财务审计" } }); //unityOfWork.SysUserRepository.Insert(new Models.SysUser { CreateDate = DateTime.Now, Email = "*****@*****.**", PassWord = "******", UserName = "******" }); //unityOfWork.Save(); try { var one = unityOfWork.SysUserRepository.GetAsNoTrcking().FirstOrDefault(t => t.ID == 1); string s = one.SysDepartment.DepartmentName; var find = unityOfWork.SysUserRepository.GetByID(1); if (find.SysDepartment.DepartmentName != null) { string departName = find.SysDepartment.DepartmentName; } var list = unityOfWork.SysUserRepository.Get(); unityOfWork.Dispose(); return(View(list)); } catch { return(null); } }
protected void Application_EndRequest() { UnityOfWork.Dispose(); }