public ActionResult Create(LootCreate model) //POST: Takes in written the information as 'model' { if (!ModelState.IsValid) { return(View(model)); // Checks if the input requirements have been met. If not, return what the user wrote in the box (error) } var service = CreateLootService(); // Service is set to the user's information (euid) if (service.CreateLoot(model)) // Sends the information to the service (CreateLoot) { TempData["SaveResult"] = $"{model.LootName} has been created."; // If it was sent, send a confirmation message return(RedirectToAction("Index")); // Returns to the index page (list view) } ; ModelState.AddModelError("", $"{model.LootName} could not be created."); return(View(model)); }
public bool CreateLoot(LootCreate model) { // Entity is loot they are making var entity = new Loot() { // Sets the class to take in the model information (What the user inputs) OwnerId = _userId, LootName = model.LootName, LootDesc = model.LootDesc, MonsterId = model.MonsterId }; // Calls the database as 'ctx' using (var ctx = new ApplicationDbContext()) { ctx.Loot.Add(entity); // Adds loot to the database return(ctx.SaveChanges() == 1); // Saves the entry } }