public ActionResult ArtifactEdit(int id, ArtifactEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.ArtifactID != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var userId = Guid.Parse(User.Identity.GetUserId()); var service = new ArtifactService(userId); if (service.UpdateArtifact(model)) { TempData["SaveResult"] = "Your Artifact was updated."; return(RedirectToAction("ArtifactIndex")); } ModelState.AddModelError("", "Your Artifact could not be updated."); return(View(model)); }
public IHttpActionResult Put(ArtifactEdit artifact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateArtifactService(); if (!service.EditArtifact(artifact)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateArtifact(ArtifactEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Artifacts .Single(e => e.ArtifactID == model.ArtifactID && e.OwnerId == _userId); entity.ArtifactType = model.ArtifactType; entity.ShortLabel = model.ShortLabel; entity.Description = model.Description; entity.Link = model.Link; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public ActionResult ArtifactEdit(int id) { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new ArtifactService(userId); var detail = service.GetArtifactById(id); var model = new ArtifactEdit { ArtifactID = detail.ArtifactID, ArtifactType = detail.ArtifactType, ShortLabel = detail.ShortLabel, Description = detail.Description, Link = detail.Link }; return(View(model)); }
public bool EditArtifact(ArtifactEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Artifacts .Single(e => e.ID == model.ID && e.OwnerID == _userID); entity.Name = model.Name; entity.Age = model.Age; entity.Power = model.Power; entity.Description = model.Description; entity.PlaceID = model.PlaceID; return(ctx.SaveChanges() == 1); } }