public ActionResult DeleteConfirmed(int id) { PartyItem partyItem = db.PartyItems.Find(id); db.PartyItems.Remove(partyItem); db.SaveChanges(); return(RedirectToAction("Index")); }
public bool CreatePartyItem(PartyItemCreate partyItemToCreate) { var entity = new PartyItem { Name = partyItemToCreate.Name, Price = partyItemToCreate.Price }; _db.PartyItems.Add(entity); return(_db.SaveChanges() == 1); }
// GET: PartyItems/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PartyItem partyItem = db.PartyItems.Find(id); if (partyItem == null) { return(HttpNotFound()); } return(View(partyItem)); }
private void HandleEvents() { _newPartyAddButton.Click += async(s, e) => { try { var location = new LocationData() { Name = ValidateTextView(_newPartyLocationEditText) }; var unixTimestamp = (Int32)(_partyTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; // Create model wrapper that'll provide proper validation var partyContent = new PartyContent() { Description = ValidateTextView(_newPartyDescriptionEditText), Image = _authLink?.User?.PhotoUrl, Items = _productList?.ToDictionary(k => Guid.NewGuid().ToString(), v => v), Location = location, Name = ValidateTextView(_newPartyNameEditText), Unix = unixTimestamp, Order = Enumerable.Range(0, _productList.Count) }; var party = new Party() { Content = partyContent }; var newPartyId = await _partyRepository.Add(party); if (newPartyId != null) { ShowDialog("Party's been added successfully", (sx, ex) => { var intent = new Intent(); intent.SetClass(this, typeof(MenuActivity)); Finish(); StartActivity(intent); }); } } catch (Exception ex) { ShowDialog("Error occurred"); Console.WriteLine(ex.Message); } }; _newPartyAddProductButton.Click += (s, e) => { try { var productName = _newPartyProductNameEditText.Text; if (String.IsNullOrWhiteSpace(productName) || productName.Length < 3) { throw new FormatException(); } var productAmount = Int32.Parse(_newPartyProductAmountEditText.Text); if (productAmount < 1) { throw new InvalidCastException(); } var product = new PartyItem { Amount = productAmount, Name = productName }; _productList.Add(product); _dataAdapter.NotifyDataSetChanged(); } catch (Exception ex) { if (ex is FormatException) { ShowDialog("Product name should be min 3 letters long"); } else if (ex is InvalidCastException) { ShowDialog("Product amount should be greater than 0"); } else { ShowDialog("Error occurred"); } Console.WriteLine(ex.Message); } }; _newPartySetDateTimeButton.Click += (s, e) => { var year = DateTime.UtcNow.Year; var month = DateTime.UtcNow.Month; var day = DateTime.UtcNow.Day; var date = new DatePickerDialog(this, this, year, month, day); date.Show(); }; }