Exemple #1
0
        public bool UpdateItem(CReminderDto item)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    CReminderDto reminder = context.CRemindersDto.Where(r => r.PersonID == item.PersonID && r.Title.Equals(item.Title)).FirstOrDefault();

                    if (reminder == null)
                    {
                        log.Info("Can't update reminder because it doesn't exist in database id = {0}, Title: {1}", item.PersonID, item.Title);
                        return(false);
                    }

                    reminder.DayOfMonth  = item.DayOfMonth;
                    reminder.Description = item.Description;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to update CReminders (id = {1} title: {2}). Message: {0}", ex.Message, item.PersonID, item.Title);
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public bool DeleteItemByKey(CReminderKey key)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    CReminderDto reminder = context.CRemindersDto.Where(r => r.PersonID == key.PersonId && r.Title.Equals(key.Title)).FirstOrDefault();
                    if (reminder == null)
                    {
                        log.Info("Can't delete reminder because it doesn't exist in database id = {0}, Title: {1}", key.PersonId, key.Title);
                        return(false);
                    }

                    context.CRemindersDto.Remove(reminder);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to delete CReminders (id = {1} title: {2}). Message: {0}", ex.Message, key.PersonId, key.Title);
                return(false);
            }

            return(true);
        }
Exemple #3
0
        public bool AddItem(CReminderDto item)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    context.CRemindersDto.Add(item);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to add CReminders into DB. Message: {0}", ex.Message);
                return(false);
            }

            return(true);
        }