Пример #1
0
        public void AddPhone(Phone phone)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                phone.PhoneId = 0;

                context.Phones.Add(phone);
                context.SaveChanges();
            }
        }
Пример #2
0
        public void AddNote(Note note)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                note.NoteId = 0;

                context.Notes.Add(note);
                context.SaveChanges();
            }
        }
Пример #3
0
        public void AddNotesRange(IEnumerable<Note> noteList)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                foreach (var note in noteList)
                {
                    note.NoteId = 0;
                    context.Notes.Add(note);
                }

                context.SaveChanges();
            }
        }
Пример #4
0
        public void AddPhonesRange(IEnumerable<Phone> phoneList)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                foreach (var phone in phoneList)
                {
                    phone.PhoneId = 0;
                    context.Phones.Add(phone);
                }

                context.SaveChanges();
            }
        }
Пример #5
0
        public void UpdatePhone(Phone phone)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                var curPhone = GetPhone(phone.PhoneId);

                curPhone.Name = phone.Name;
                curPhone.Number = phone.Number;

                context.SaveChanges();
            }
        }
Пример #6
0
        public void UpdateNote(Note note)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                var curNote = GetNote(note.NoteId);

                curNote.Text = note.Text;
                curNote.Moment = note.Moment;
                curNote.TargetComputer = note.TargetComputer;

                context.SaveChanges();
            }
        }
Пример #7
0
 public void SaveChanges()
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         context.SaveChanges();
     }
 }
Пример #8
0
 public Note FindNote(string text)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Notes.FirstOrDefault(n => n.Text == text);
     }
 }
Пример #9
0
 public bool ContainsNote(Note note)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Notes.FirstOrDefault(n =>
             n.Moment == note.Moment &&
             n.TargetComputer == note.TargetComputer &&
             n.Text == note.Text) != null;
     }
 }
Пример #10
0
 public void RecreateDb()
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         context.Database.Delete();
         context.Database.CreateIfNotExists();
     }
 }
Пример #11
0
 public Phone GetPhone(int phoneId)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.FirstOrDefault(p => p.PhoneId == phoneId);
     }
 }
Пример #12
0
 public Note GetNote(int noteId)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Notes.FirstOrDefault(n => n.NoteId == noteId);
     }
 }
Пример #13
0
 public Phone GetFirstFiltredPhone(Func<Phone, bool> condition)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.ToList().FirstOrDefault(condition);
     }
 }
Пример #14
0
 public List<Phone> GetFiltredPhones(Func<Phone, bool> condition)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.ToList().Where(condition).ToList();
     }
 }
Пример #15
0
 public List<Phone> GetAllPhones()
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.ToList();
     }
 }
Пример #16
0
 public Phone FindPhone(string name)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.FirstOrDefault(p => p.Name == name);
     }
 }
Пример #17
0
        public void RemoveNote(int noteId)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                var note = context.Notes.FirstOrDefault(n => n.NoteId == noteId);

                context.Notes.Remove(note);
                context.SaveChanges();
            }
        }
Пример #18
0
        public void RemovePhone(int phoneId)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                var phone = context.Phones.FirstOrDefault(p => p.PhoneId == phoneId);

                context.Phones.Remove(phone);
                context.SaveChanges();
            }
        }
Пример #19
0
 public bool ContainsNote(DateTime moment, string targetComputer, string text)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Notes.FirstOrDefault(n =>
             n.Moment == moment &&
             n.TargetComputer == targetComputer &&
             n.Text == text) != null;
     }
 }
Пример #20
0
        public bool ContainsNote(string noteView)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                var parts = noteView.Split('@');
                if (parts.Length != 3)
                {
                    return false;
                }

                var moment = parts[0] != "" ?
                    DateTime.ParseExact(parts[0], "dd.MM.yyyy H:mm:ss", CultureInfo.InvariantCulture) :
                    new DateTime(1970, 1, 1);
                var text = parts[1];
                var targetComputer = parts[2];

                return context.Notes.FirstOrDefault(n =>
                    n.Moment.Equals(moment) &&
                    n.TargetComputer == targetComputer &&
                    n.Text == text) != null;
            }
        }