public async Task <IActionResult> Create(Hobbie hobby) { _db.Hobbies.Add(hobby); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <HobbieViewModel> addHobbie(HobbieViewModel model) { await addHobbieValidation(model); try { var hobbie = new Hobbie() { userId = model.userId, hobbie = model.hobbie }; await db.AddAsync(hobbie); var result = (await db.SaveChangesAsync()) > 0; if (!result) { throw new Exception("Add hobbie null"); } return(new HobbieViewModel { id = hobbie.id, userId = hobbie.userId, hobbie = hobbie.hobbie }); } catch (Exception ex) { log.error("Delete hobbie error - {0}", ex: ex, model); return(null); } }
public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } Hobbie hobby = await _db.Hobbies.FindAsync(id); if (hobby == null) { return(NotFound()); } return(View(hobby)); }
protected void OnDoneButtonClicked(object sender, EventArgs e) { string ty = Typebox.ActiveText; int id = Locals.Count + 1; if (ty == "Cine") { Cine cine = new Cine(NameBox.Text, id, HoursBox.Text, OwnerBox.Text, ScreenSpin.ValueAsInt); LocalController.Locals.Add(cine); } else if (ty == "Hobbie") { Hobbie hobbie = new Hobbie(NameBox.Text, id, HoursBox.Text, OwnerBox.Text); LocalController.Locals.Add(hobbie); } else if (ty == "Restaurant") { Restaurant restaurant = new Restaurant(NameBox.Text, id, HoursBox.Text, OwnerBox.Text, ExTablesButton.Active); LocalController.Locals.Add(restaurant); } else if (ty == "Store") { string cats = CatBox.Text; List <string> x = new List <string>(); foreach (string cat in cats.Split(',')) { x.Add(cat); } Store store = new Store(NameBox.Text, id, HoursBox.Text, OwnerBox.Text, x); LocalController.Locals.Add(store); } int id2 = LocalController.Locals.Count; DoneLabel.Text = $"Local N˚ {id2} created!\n"; Dictionary <int, Dictionary <string, string> > dict = LocalController.FillDict(); string name = $"Name: {dict[id2]["Name"]}\n"; string owner = $"Owner: {dict[id2]["Owner"]}\n"; string bh = $"Business Hours: {dict[id2]["Business Hours"]}\n"; DoneLabel.Text += name; DoneLabel.Text += owner; DoneLabel.Text += bh; DoneLabel.Show(); Back(); }
public async Task <IActionResult> DeleteHobby(int?id) { if (id == null) { return(NotFound()); } Hobbie hobby = await _db.Hobbies.FindAsync(id); if (hobby == null) { return(NotFound()); } _db.Hobbies.Remove(hobby); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public void Update(Hobbie entity) { _hobbieDAL.Update(entity); }
public void Insert(Hobbie entity) { _hobbieDAL.Add(entity); }
public void Delete(Hobbie entity) { _hobbieDAL.Delete(entity); }