public async Task RemoveTelephoneNote(TelephoneNote telephoneNote)
 {
     using (var db = new ApplicationContext())
     {
         db.TelephoneNotes.Remove(db.TelephoneNotes.Find(telephoneNote.Id));
         await db.SaveChangesAsync();
     }
 }
 public async Task AddTelephoneNote(TelephoneNote telephoneNote)
 {
     using (var db = new ApplicationContext())
     {
         db.TelephoneNotes.Add(telephoneNote);
         await db.SaveChangesAsync();
     }
 }
        public string UpdDict(string name, string phone)
        {
            var note = new TelephoneNote(name, phone);

            telephoneRepository.UpdateTelephoneNote(note).GetAwaiter();

            return("OK");
        }
예제 #4
0
        public void Update([FromBody] TelephoneNote item)
        {
            TelephoneNote newContact = Get(item.Name);

            newContact.Phone = item.Phone;

            string json = JsonConvert.SerializeObject(Contacts);

            File.WriteAllText(file, json);
        }
        public string DelDict(string name)
        {
            var note = new TelephoneNote()
            {
                Name = name
            };

            telephoneRepository.RemoveTelephoneNote(note).GetAwaiter();

            return("OK");
        }
예제 #6
0
        public TelephoneNote Add([FromBody] TelephoneNote item)
        {
            Contacts.Add(new TelephoneNote {
                Name = item.Name, Phone = item.Phone
            });

            string json = JsonConvert.SerializeObject(Contacts);

            File.WriteAllText(file, json);

            return(item);
        }
        public async Task UpdateTelephoneNote(TelephoneNote telephoneNote)
        {
            using (var db = new ApplicationContext())
            {
                var updatedNote = db.TelephoneNotes.FirstOrDefault(x => x.Id == telephoneNote.Id);

                updatedNote.Name  = telephoneNote.Name;
                updatedNote.Phone = telephoneNote.Phone;

                await db.SaveChangesAsync();
            }
        }
예제 #8
0
        public async Task <ActionResult> Delete(TelephoneNote telephoneNote)
        {
            try
            {
                await repository.RemoveTelephoneNote(telephoneNote);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
예제 #9
0
        public async Task <ActionResult> Update(TelephoneNote telephoneNote)
        {
            try
            {
                await telephoneRepository.UpdateTelephoneNote(telephoneNote);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #10
0
        public async Task <ActionResult> Create(TelephoneNote telephoneNote)
        {
            try
            {
                await telephoneRepository.AddTelephoneNote(telephoneNote);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
예제 #11
0
        public async Task RemoveTelephoneNote(TelephoneNote telephoneNote)
        {
            List <TelephoneNote> noteList = await GetTelephoneNotes();

            noteList.RemoveAll(x => x.Id == telephoneNote.Id);

            using (var fs = new FileStream(path, FileMode.Truncate))
            {
                await JsonSerializer.SerializeAsync(fs, noteList);

                fs.Close();
            }
        }
예제 #12
0
        public async Task <ActionResult> Delete(TelephoneNote telephoneNote)
        {
            try
            {
                telephoneNote = (await telephoneRepository.GetTelephoneNotes()).FindLast(x => x.Name == telephoneNote.Name);
                await telephoneRepository.RemoveTelephoneNote(telephoneNote);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
예제 #13
0
        private void Delete_Click(object sender, EventArgs e)
        {
            try
            {
                var telephoneNote = new TelephoneNote()
                {
                    Namek__BackingField  = this.name.Text,
                    Phonek__BackingField = this.number.Text
                };

                this.client.Delete(telephoneNote);
                Get_Click(sender, e);
            }
            catch (Exception exp)
            {
                MessageBox.Show("Fill required fields");
            }
        }
예제 #14
0
        public async Task AddTelephoneNote(TelephoneNote telephoneNote)
        {
            List <TelephoneNote> noteList;

            try
            {
                noteList = await GetTelephoneNotes();

                telephoneNote.Id = noteList.Max(x => x.Id) + 1;
            }
            catch
            {
                noteList         = new List <TelephoneNote>();
                telephoneNote.Id = 1;
            }

            noteList.Add(telephoneNote);
            using (var fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                await JsonSerializer.SerializeAsync(fs, noteList);

                fs.Close();
            }
        }
예제 #15
0
 public async Task UpdateTelephoneNote(TelephoneNote telephoneNote)
 {
     await RemoveTelephoneNote(telephoneNote);
     await AddTelephoneNote(telephoneNote);
 }
예제 #16
0
 public async Task RemoveTelephoneNote(TelephoneNote telephoneNote)
 {
     await _telephoneManager.RemoveTelephoneNote(telephoneNote);
 }
예제 #17
0
 public async Task AddTelephoneNote(TelephoneNote telephoneNote)
 {
     await _telephoneManager.AddTelephoneNote(telephoneNote);
 }
 public void Update(TelephoneNote telephoneNote)
 {
     telephoneRepository.UpdateTelephoneNote(telephoneNote);
 }
예제 #19
0
 public async Task UpdateTelephoneNote(TelephoneNote telephoneNote)
 {
     await _telephoneManager.UpdateTelephoneNote(telephoneNote);
 }
예제 #20
0
 // PUT api/values/5
 public void Put(int id, [FromBody] TelephoneNote value)
 {
 }
예제 #21
0
 // POST api/values
 public void Post([FromBody] TelephoneNote value)
 {
 }
예제 #22
0
 public void Delete([FromBody] TelephoneNote telephoneNote)
 {
     telephoneNote = (telephoneRepository.GetTelephoneNotes().GetAwaiter().GetResult()).FindLast(x => x.Name == telephoneNote.Name);
     telephoneRepository.RemoveTelephoneNote(telephoneNote);
 }
예제 #23
0
 public void Update([FromBody] TelephoneNote telephoneNote)
 {
     telephoneRepository.UpdateTelephoneNote(telephoneNote);
 }
 public void Delete(TelephoneNote telephoneNote)
 {
     telephoneRepository.RemoveTelephoneNote(telephoneNote).GetAwaiter().GetResult();
 }
예제 #25
0
        public void Create([FromBody] TelephoneNote telephoneNote)
        {
            var x = Request;

            telephoneRepository.AddTelephoneNote(telephoneNote);
        }
 public void Add(TelephoneNote telephoneNote)
 {
     telephoneRepository.AddTelephoneNote(telephoneNote).GetAwaiter().GetResult();
 }