public ActionResult Create(HiveCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new HiveService(); if (service.CreateHive(model)) { TempData["SaveResult"] = "Your hive was created. May the flow be aplenty."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Hive could not be created."); return(View(model)); }
public bool CreateHive(HiveCreate model) { var entity = new Hive() { OwnerId = _userId, HiveName = model.HiveName, OriginDate = model.OriginDate, NumberOfDeeps = model.NumberOfDeeps, Status = model.Status, LocationId = model.LocationId }; using (var ctx = new ApplicationDbContext()) //only working with empty ctor but won't actually add/save { ctx.Hives.Add(entity); return(ctx.SaveChanges() == 1); } }