public bool DeleteItemByKey(CPersonalTargetKey key)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    CPersonalTargetDto target = context.CPersonalTargetsDto.Where(t => t.PersonID == key.PersonId &&
                                                                                  t.CategoryID == key.CategoryId &&
                                                                                  t.Month == key.Month)
                                                .FirstOrDefault();
                    if (target == null)
                    {
                        log.Info("Can't delete CPersonalTarget because it doesn't exist in database (PersonId = {0}, categoryId = {1}, date = {2})",
                                 key.PersonId, key.CategoryId, key.Month);
                        return(false);
                    }

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

            return(true);
        }
 public CPersonalTargetDto FindItemByKey(CPersonalTargetKey key)
 {
     try
     {
         using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
         {
             return(context.CPersonalTargetsDto.Where(t => t.PersonID == key.PersonId &&
                                                      t.CategoryID == key.CategoryId &&
                                                      t.Month == key.Month)
                    .FirstOrDefault());
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Some error occure while trying to find CPersonalTargets by key (PersonId = {1}, categoryId = {2}, date = {3}). Message: {0}",
                   ex.Message, key.PersonId, key.CategoryId, key.Month);
         return(null);
     }
 }