Ejemplo n.º 1
0
        public bool DeleteItemByKey(FamilyTargetKey key)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    CFamilyTargetDto target = context.CFamilyTargetsDto.Where(t => t.FamilyID == key.FamilyId &&
                                                                              t.CategoryID == key.CategoryId &&
                                                                              t.Month == key.Month)
                                              .FirstOrDefault();
                    if (target == null)
                    {
                        log.Info("Can't delete CFamilyTargets because it doesn't exist in database (FamilyId = {0}, categoryId = {1}, date = {2})",
                                 key.FamilyId, key.CategoryId, key.Month);
                        return(false);
                    }

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

            return(true);
        }
Ejemplo n.º 2
0
 public CFamilyTargetDto FindItemByKey(FamilyTargetKey key)
 {
     try
     {
         using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
         {
             return(context.CFamilyTargetsDto.Where(t => t.FamilyID == key.FamilyId &&
                                                    t.CategoryID == key.CategoryId &&
                                                    t.Month == key.Month)
                    .FirstOrDefault());
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Some error occure while trying to find CFamilyTargets by key (FamilyId = {1}, categoryId = {2}, date = {3}). Message: {0}",
                   ex.Message, key.FamilyId, key.CategoryId, key.Month);
         return(null);
     }
 }