private void LViewEventSelectionChanged(object sender, SelectionChangedEventArgs e) { if (LViewEvent.SelectedIndex >= 0) { MessageBoxResult x = MessageBox.Show("Вы действительно купить?", "Выйти", MessageBoxButton.YesNo, MessageBoxImage.Question); if (x == MessageBoxResult.Yes) { var user = Manager.idUser; Event eve = (LViewEvent.SelectedItem as Event); List <User> users = TatarCulturDbEntities.GetContext().Users.ToList(); _currentUser = users.FirstOrDefault(p => p.IdUser == user); var keys = TatarCulturDbEntities.GetContext().Keys.Where(p => p.IdEvent == eve.IdEvent).ToList(); var key = keys.FirstOrDefault(p => p.Active == false); var coin = eve.Coin - _currentUser.Coin; StringBuilder s = new StringBuilder(); if (_currentUser.Coin == null) { s.AppendLine("У вас не хватает монет"); } if (_currentUser.Coin < eve.Coin) { s.AppendLine("У вас не хватает монет"); } if (_currentUser.Coin == 0) { s.AppendLine("У вас нет монет"); } if (s.Length > 0) { MessageBox.Show(s.ToString()); return; } if (_currentSale.IdSale == 0) { _currentSale.SaleDate = DateTime.Now; _currentUser.Coin = _currentUser.Coin - coin; _currentSale.IdKey = key.IdKey; _currentSale.IdUser = user; TatarCulturDbEntities.GetContext().Sales.Add(_currentSale); _currentKey = key; _currentKey.Active = true; } try { TatarCulturDbEntities.GetContext().SaveChanges(); MessageBox.Show($"Куплено!"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } } }
public async Task <JsonResult> Put([FromBody] Models.Key model, int id) { var key = Database.Key .Include(k => k.Type) .Where(k => k.Id == id) .FirstOrDefault(); key.Name = model.Name; key.TypeId = model.Type.Id; await Database.SaveChangesAsync(); return(Get(key.Id)); }
public async Task <JsonResult> Post([FromBody] Models.Key model) { Key key = new Key { UserId = model.UserId, TypeId = model.Type.Id, Name = model.Name, Content = "" }; Database.Key.Add(key); await Database.SaveChangesAsync(); key.Content = Hash(key.Id); await Database.SaveChangesAsync(); return(Get(key.Id)); }
/// <summary> /// Removes the specified item from the keys. /// </summary> /// <param name="key">The specific item to be removed</param> public void RemoveKey(Models.Key key) { grdKeys.Children.Remove(grdKeys.Children[1]); Keys.Remove(key); FillListView(); }