public void Create(User item) { dbContext.Set <User>().Add(item); dbContext.SaveChanges(); Limitation limitation = new Limitation(); limitation.Limit = 10000; limitation.UserId = item.Id; dbContext.Set <Limitation>().Add(limitation); dbContext.SaveChanges(); }
/// <summary> /// Logic for button (save new dream in database and on dream page) /// </summary> private void add_Click(object sender, RoutedEventArgs e) { if (dbContext.Set <Dream>().Where(d => d.UserId == controller.user.Id).ToList().Count != 0) { dbContext.Set <Dream>().RemoveRange(dbContext.Set <Dream>().Where(d => d.UserId == controller.user.Id)); } dreamPage.dreamName = DreamName.Text; dreamPage.dreamPrice = Double.Parse(DreamPrice.Text); dreamPage.dreamNameLabel.Content = dreamPage.dreamName + " " + dreamPage.dreamPrice; if (Double.TryParse(DreamPrice.Text, out double amount)) { Dream dream = new Dream(); dream.UserId = controller.user.Id; dream.Name = DreamName.Text; dream.Price = amount; dbContext.Set <Dream>().Add(dream); dbContext.SaveChanges(); dreamPage.UpdateProgressBar(); this.Close(); } else { MessageBox.Show("Wrong price entered"); } }
private void Add_Click(object sender, RoutedEventArgs e) { // Validation of field price if (Double.TryParse(price.Text, out double amount)) { CategoryRepository categories = new CategoryRepository(); Category cat = categories.GetItems().Find(c => c.Name == category); // Adding new expense to database Expense expense = new Expense(); expense.CategoryId = cat.Id; expense.AmountOfMoney = amount; expense.Date = date; expense.UserId = controller.user.Id; dbContext.Set <Expense>().Add(expense); dbContext.SaveChanges(); // Updating progress bar expensePage.SetProgressBar(date); this.Close(); } else { MessageBox.Show("Wrong price entered"); } }
private void SignUpButton_Click(object sender, RoutedEventArgs e) { bool checkPassed = true; // Check data and write to db: checkPassed &= name.Text.Length != 0 && !App.ContainNumbers(name.Text); checkPassed &= surname.Text.Length != 0 && !App.ContainNumbers(surname.Text); checkPassed &= mail.Text.Length != 0 && App.ContainAtSign(mail.Text); checkPassed &= (String.Equals(savedPassword, savedConfirmPassword) && savedPassword.Length != 0 && savedConfirmPassword.Length != 0); if (checkPassed) { User u = dbContext.Set <User>().ToList().Find(u => (u.Email == mail.Text)); if (u == null) { User user = new User { Name = name.Text, Surname = surname.Text, Email = mail.Text, Password = savedPassword }; dbContext.Set <User>().Add(user); dbContext.SaveChanges(); controller.user = user; controller.OpenPage(MainWindow.pages.home); } else { MessageBox.Show("User with entered email is already exist"); } } else { MessageBox.Show("Check data failed"); } }
private void Add_Income_Click(object sender, RoutedEventArgs e) { if (Double.TryParse(price.Text, out double amount)) { Category categ = database_variable.Set <Category>().ToList().Find(a => a.Name == category); Income new_income = new Income(); new_income.CategoryId = categ.Id; new_income.MoneyCount = Double.Parse(price.Text); new_income.Date = date; new_income.UserId = controller.user.Id; new_income.CategoryCheck = categ.CategoryType; database_variable.Set <Income>().Add(new_income); database_variable.SaveChanges(); incomePage.ShowResult(new_income.MoneyCount, new_income.CategoryCheck); this.Close(); } else { MessageBox.Show("Wrong price entered!"); } }
public void Create(Expense item) { dbContext.Set <Expense>().Add(item); dbContext.SaveChanges(); }
public void Update(Limitation item) { dbContext.Entry(item).State = EntityState.Modified; dbContext.SaveChanges(); }
public void Create(Income item) { dbContext.Set <Income>().Add(item); dbContext.SaveChanges(); }
public void Create(User item) { dbContext.Set <User>().Add(item); dbContext.SaveChanges(); }
public void Create(Category item) { dbContext.Set <Category>().Add(item); dbContext.SaveChanges(); }