public ActionResult Create(int id) { var model = new ActionCreate() { LarderID = id }; return(View(model)); }
public bool CreateAction(ActionCreate model) { var entity = new Data.Models.Action() { AuthorID = userId, Description = model.Description, LarderId = model.LarderID }; using (var context = new CookbookContext()) { context.Actions.Add(entity); return(context.SaveChanges() == 1); } }
public IHttpActionResult Post(int locationid, ActionCreate action) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateActionService(); if (!service.CreateAction(locationid, action)) { return(InternalServerError()); } return(Ok()); }
public ActionResult Create(ActionCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateActionService(); if (service.CreateAction(model)) { TempData["SaveResult"] = "Step was created."; return(RedirectToAction("Create", model.LarderID)); } else { ModelState.AddModelError("", "Step could not be created."); return(View(model)); } }
public bool CreateAction(int locationid, ActionCreate model) { var entity = new Data.Actionz() //"Data". resolves error that states ambiguous reference between PurpleRain.Data.Action and System.Action { Activity = model.Activity, }; using (var ctx = new ApplicationDbContext()) { ctx.Action.Add(entity); if (ctx.SaveChanges() == 1) { var locations = ctx .Locations .Single(e => e.LocationID == locationid && e.OwnerID == _userId); locations.ActivityID = entity.ActivityID; return(ctx.SaveChanges() == 1); } return(false); } }