Beispiel #1
0
        public void AddPhone(Phone phone)
        {
            using (var context = new UchOtdContext(ConnectionString))
            {
                phone.PhoneId = 0;

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

                context.Notes.Add(note);
                context.SaveChanges();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #7
0
 public void SaveChanges()
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         context.SaveChanges();
     }
 }
Beispiel #8
0
 public Note FindNote(string text)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Notes.FirstOrDefault(n => n.Text == text);
     }
 }
Beispiel #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;
     }
 }
Beispiel #10
0
 public void RecreateDb()
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         context.Database.Delete();
         context.Database.CreateIfNotExists();
     }
 }
Beispiel #11
0
 public Phone GetPhone(int phoneId)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.FirstOrDefault(p => p.PhoneId == phoneId);
     }
 }
Beispiel #12
0
 public Note GetNote(int noteId)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Notes.FirstOrDefault(n => n.NoteId == noteId);
     }
 }
Beispiel #13
0
 public Phone GetFirstFiltredPhone(Func<Phone, bool> condition)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.ToList().FirstOrDefault(condition);
     }
 }
Beispiel #14
0
 public List<Phone> GetFiltredPhones(Func<Phone, bool> condition)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.ToList().Where(condition).ToList();
     }
 }
Beispiel #15
0
 public List<Phone> GetAllPhones()
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.ToList();
     }
 }
Beispiel #16
0
 public Phone FindPhone(string name)
 {
     using (var context = new UchOtdContext(ConnectionString))
     {
         return context.Phones.FirstOrDefault(p => p.Name == name);
     }
 }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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;
     }
 }
Beispiel #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;
            }
        }