public void DeletePossession(string possessionName, int userId) { int possessionId = _DboContext.PossessionsData.First(u => u.Name == possessionName).ID; var toDelete = _DboContext.Possessions.Where(x => x.UserID == userId && x.PossessionDataID == possessionId).FirstOrDefault(); _DboContext.Remove(toDelete); _DboContext.SaveChanges(); }
public void AddNewGoal(string inputName, float inputAmount, string inputDescription, int userId) { if (inputName != "" && inputDescription != "") { // Checks whether transaction amount is a number if (inputAmount < 0) { throw new ArgumentException("Provided amount can't be negative"); } DboGoal newTransaction = new DboGoal(); DboGoal dboGoal = new DboGoal { GoalItemName = inputName, GoalItemPrice = inputAmount, GoalDescription = inputDescription, UserId = userId }; _DboContext.Goals.Add(dboGoal); _DboContext.SaveChanges(); } }
public void AddNewTransaction(TransactionType transactType, string transactionName, string transactionAmount, DateTime date, int userID, string category = "N/A") { if (transactionName != "" && transactionAmount != "") { // Checks whether transaction amount is a number float transAmount; if (!float.TryParse(transactionAmount, out transAmount)) { return; } if (transAmount < 0) { throw new ArgumentException("Provided amount can't be negative"); } // Check if category exists TransactionCategoriesMeshed categories = _CategoryService.GetTransactionCategories(); if (!categories.IncomeCategories.Exists(x => x.Name == category) && !categories.ExpensesCategories.Exists(x => x.Name == category)) { throw new BadCategoryException("Category not found: ", category); } //Transaction newTransaction = new Transaction(transactType, transAmount, transactionName, category, DateTime.Now); //List.Add(newTransaction); //OnTransactionAdded(newTransaction); DboTransaction dbotransaction = new DboTransaction { TransactType = transactType, Title = transactionName, Category = category, Date = (date == null) ? DateTime.Now : date, Amount = transAmount, UserId = userID }; _dboContext.Transactions.Add(dbotransaction); _dboContext.SaveChanges(); //SerializeTransactionList(); } }