Esempio n. 1
0
        public ActionResult Delete(int id)
        {
            var contact = _PhoneBookService.GetById(id);

            try
            {
                _PhoneBookService.Delete(contact);

                var records = _PhoneBookEntryService.GetRecordsByPhoneBookId(contact.Id).ToList();

                if (records != null && records.Count() > 0)
                {
                    foreach (var record in records)
                    {
                        _PhoneBookEntryService.Delete(record);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error($"Contact {contact.Name} {contact.Surname} was not deleted, something went wrong!", ex);

                Danger($"Contact {contact.Name} {contact.Surname} was not deleted, something went wrong!", true);

                return(View(contact));
            }

            Success(string.Format("<b>{0}</b> was successfully deleted.", contact.Name), true);

            PhonebookHub.BroadcastData();

            return(RedirectToAction("Index", "Phonebook"));
        }
Esempio n. 2
0
        public ActionResult Add(PhonebookEditViewModel phonebookEditViewModel)
        {
            var contact = new PhoneBook()
            {
                Name        = phonebookEditViewModel.FirstName,
                Surname     = phonebookEditViewModel.LastName,
                CreatedDate = DateTime.Now
            };

            _PhoneBookService.Create(contact);

            var Id = contact.Id;

            if (Id == 0)
            {
                log.Error("Contact not saved. Please try again later!");
                Danger("Contact not saved. Please try again later!");
                return(View("PhoneBookView", phonebookEditViewModel));
            }

            if (phonebookEditViewModel.Numbers.Count() > 0)
            {
                foreach (var entry in phonebookEditViewModel.Numbers)
                {
                    var phonebookEntry = new PhoneBookEntry()
                    {
                        PhoneBookId     = Id,
                        PhoneBookTypeId = Convert.ToInt32(entry.PhoneBookTypeId),
                        Number          = entry.Number
                    };

                    _PhoneBookEntryService.Create(phonebookEntry);
                    Id = phonebookEntry.Id;

                    if (Id == 0)
                    {
                        log.Error($"Contact number {entry.Number} not saved {phonebookEditViewModel.FirstName}!");

                        Danger($"Contact number {entry.Number} not saved {phonebookEditViewModel.FirstName}!");

                        return(View("PhoneBookView", phonebookEditViewModel));
                    }
                }
            }

            Success(string.Format("<b>{0}</b> was successfully saved to the Phonebook.", phonebookEditViewModel.FirstName), true);

            PhonebookHub.BroadcastData();

            return(RedirectToAction("Index", "Phonebook"));
        }
Esempio n. 3
0
        public ActionResult Update(PhonebookEditViewModel phonebookEditViewModel)
        {
            if (phonebookEditViewModel.Numbers.Count() > 0)
            {
                foreach (var entry in phonebookEditViewModel.Numbers)
                {
                    var record = _PhoneBookEntryService.GetById(entry.Id);

                    record.Number          = entry.Number;
                    record.PhoneBookTypeId = Convert.ToInt32(entry.PhoneBookTypeId);

                    _PhoneBookEntryService.Update(record);
                }
            }

            Success(string.Format("<b>{0}</b> was successfully updated.", phonebookEditViewModel.FirstName), true);

            PhonebookHub.BroadcastData();

            return(RedirectToAction("Index", "Phonebook"));
        }