public bool DeleteItemByKey(CSpendingHistoryKey key)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    CSpendingHistoryDto spendingHistory = context.CSpendingHistoriesDto.Where(h => h.PersonID == key.PersonId &&
                                                                                              h.CategoryID == key.CategoryId &&
                                                                                              h.Month == key.Month)
                                                          .FirstOrDefault();
                    if (spendingHistory == null)
                    {
                        log.Info("Can't Delete SpendingHistory because it doesn't exist in database (personId = {0}, categoryId = {1}, Month: {2})",
                                 key.PersonId, key.CategoryId, key.Month);
                        return(false);
                    }

                    context.CSpendingHistoriesDto.Remove(spendingHistory);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to delete SpendingHistory (personId = {1}, categoryId = {2}, Month: {3}). Message: {0}",
                          ex.Message, key.PersonId, key.CategoryId, key.Month);
                return(false);
            }

            return(true);
        }
 public CSpendingHistoryDto FindItemByKey(CSpendingHistoryKey key)
 {
     try
     {
         using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
             return(context.CSpendingHistoriesDto.Where(h => h.PersonID == key.PersonId &&
                                                        h.CategoryID == key.CategoryId &&
                                                        h.Month == key.Month)
                    .FirstOrDefault());
     }
     catch (Exception ex)
     {
         log.Error(ex, "Some error occure while trying to find SpendingHistory in DB (personId = {1}, categoryId = {2}, Month: {3}). Message: {0}",
                   ex.Message, key.PersonId, key.CategoryId, key.Month);
         return(null);
     }
 }