public virtual ActionResult Remove(string id) { int nId = 0; int.TryParse(id, out nId); if (nId != 0) { var item = model.Find(nId); con.Entry(item).State = System.Data.Entity.EntityState.Deleted; con.SaveChanges(); } return(Redirect(Request.UrlReferrer.ToString())); }
public void SetCurrentUserFromIdentity() { // ユーザー情報 // 企業ユーザーの場合は会社情報も取得 var p = _context.User.Identity; if (p.IsAuthenticated) { using (var db = new Models.Entities()) { db.Configuration.ProxyCreationEnabled = false; // TODO: UserNameの一意性保証 this.CurrentUser = db.Users.FirstOrDefault(x => x.UserName == p.Name); var au = this.CurrentUser as Models.AccountUser; if (au != null) { db.Entry(au).Reference(x => x.Company).Load(); } } } if (this.CurrentUser == null) { // 未認証とする this.CurrentUser = Models.User.Anonymous; if (p.IsAuthenticated) { // 認証クッキーが有効だが、DBにユーザーが存在しない場合の対処 var identity = new System.Security.Principal.GenericIdentity(""); var principal = new System.Security.Principal.GenericPrincipal(identity, null); _context.User = principal; } } }
public void SetCurrentUserFromIdentity() { // ユーザー情報 // 企業ユーザーの場合は会社情報も取得 var p = _context.User.Identity; if (p.IsAuthenticated) { using (var db = new Models.Entities()) { db.Configuration.ProxyCreationEnabled = false; // TODO: UserNameの一意性保証 this.CurrentUser = db.Users.FirstOrDefault(x => x.UserName == p.Name); var au = this.CurrentUser as Models.AccountUser; if (au != null) { db.Entry(au).Reference(x => x.Company).Load(); } } } if (this.CurrentUser == null) { // 未認証とする this.CurrentUser = Models.User.Anonymous; if (p.IsAuthenticated) { // 認証クッキーが有効だが、DBにユーザーが存在しない場合の対処 var identity = new System.Security.Principal.GenericIdentity(""); var principal = new System.Security.Principal.GenericPrincipal(identity, null); _context.User = principal; } } }
public void Task(Models.Entities con, Test_Schedule model, Mutex mutex, bool saveFlags) { try { if (saveFlags) { model.Flag_Start = 1; con.SaveChanges(); } var db = model.Test_Db; var url = model.Test_Url; var users = model.Test_Url.Test_User; foreach (var tgRef in model.Test_Group.Test_Group_Ref) { foreach (var user in users) { var result = new AspMvcEf.Models.Test_Result() { Id = 0, Test_Schedule_Id = model.Id, Test_Group_Id = tgRef.Test_Group_Id, Test_Id = tgRef.Test_Id, Flag_Ok = null, Result = null, Time_Start = DateTime.Now, Time_Stop = null }; try { //Models.SeleniumTest.Run(tgRef.Test.Test_Type.Type, tgRef.Test.Insurance_Id, user.Username, user.Password, url.Url, db.CisConnectionString, db.WebConnectionString); result.Result = ""; result.Flag_Ok = 1; } catch (Exception e) { result.Result = e.ToString(); result.Flag_Ok = 0; } result.Time_Stop = DateTime.Now; con.Entry(result).State = System.Data.Entity.EntityState.Added; con.SaveChanges(); } } if (saveFlags) { model.Flag_Stop = 1; con.SaveChanges(); } } finally { mutex.Close(); } }
public ActionResult Edit(Models.Recipes recipe, HttpPostedFileBase image1) { if (ModelState.IsValid) { recipe.recipe_date = DateTime.Now; if (image1 != null) { recipe.picture = new byte[image1.ContentLength]; image1.InputStream.Read(recipe.picture, 0, image1.ContentLength); } db.Entry(recipe).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("YourRecView")); } return(View("YourRecView")); }