public ActionResult Create(TestCreateModel model) { using (var client = new ApplicationDbContext()) { if (client.ThreadEntities.Any(t => t.ThreadId == model.View.ThreadId) == false) { ModelState.AddModelError("View.ThreadId", "thread not found"); return(View()); } var test = TestEntity.Factory(model.View, User.GetGuidUserId()); client.TestEntities.Add(test); client.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult Create(TestCreateModel test) { if (this.ModelState.IsValid) { var entity = this.Mapper.Map<Test>(test); entity.UserId = this.User.Identity.GetUserId(); this.Tests.Create(entity); try { this.Tests.SaveChanges(); } catch (Exception ex) { throw ex; } } return RedirectToAction("Index", "Home"); }
public ActionResult Edit(TestCreateModel test) { if (this.ModelState.IsValid) { var entity = this.Tests.GetAll().FirstOrDefault(x => x.Id == test.Id); if (!(this.User.Identity.GetUserName() == entity.User.UserName || this.User.IsInRole(GlobalConstants.AdministratorRoleName))) { //TODO: unauthorized error return this.RedirectToAction("Index", "Home"); } entity.Altitude = test.Altitude; entity.DangerLevel = test.DangerLevel; entity.Latitude = test.Latitude; entity.Longitude = test.Longitude; entity.TestResultsDescription = test.TestResultsDescription; entity.Place = test.Place; this.Tests.Update(entity); this.Tests.SaveChanges(); } return this.RedirectToAction("Index", "Home"); }