예제 #1
0
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            Contact contact = await contactManager.Get(id);

            await contactManager.Delete(contact);

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public Infrastructure.ValidationError[] Delete(string id)
        {
            Guid guid = new Guid();

            Guid.TryParse(id, out guid);
            if (guid != Guid.Empty)
            {
                return(contactManager.Delete(Guid.Parse(id)));
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        public ActionResult Delete(int messageId)
        {
            bool result = _contactManager.Delete(messageId);

            if (result)
            {
                TempData["Alert"] = SetAlert.Set("Poprawnie usunięto wiadomość!", "Sukces", AlertType.Success);
            }
            else
            {
                TempData["Alert"] = SetAlert.Set("Wystąpił błąd", "Błąd", AlertType.Danger);
            }

            return(RedirectToAction("Index"));
        }
 public async Task <ApiResponse> Delete(long id)
 => await _contactManager.Delete(id);
 /// <summary>
 /// Delete contact
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public ActionResult Delete(int Id)
 {
     _iContactManager.Delete(Id);
     //TODO: Suscess result messgae generic
     return(RedirectToAction("Index"));
 }
예제 #6
0
        static void Main(string[] args)
        {
_start:

            try
            {
                _contactManager = new ContactManager();
                string input = string.Empty;

                Console.WriteLine("WELCOME TO CONTACT BOOK");
                Console.WriteLine("Enter a command..");

                input = Console.ReadLine().ToLower();
                if (input == "add")
                {
                    // add new contact here

                    // accept all parameters to fit model here using Console.ReadLine() for each property one by one

                    var contact = new ContactModel();

                    Console.WriteLine("Enter Name:");
                    contact.Name = Console.ReadLine();

                    Console.WriteLine("Enter Phone Number:");
                    contact.PhoneNumber = Console.ReadLine();

                    Console.WriteLine("Enter Email Address:");
                    contact.EmailAddress = Console.ReadLine();

                    // save contact
                    bool result = _contactManager.Save(contact);

                    if (result == true)
                    {
                        Console.WriteLine("Contact has been saved OK");
                    }
                    else
                    {
                        Console.WriteLine("Unable to save contact details");
                    }
                }
                else if (input.StartsWith("get")) // e.g: get 1 (retrieves contact with ID=1)
                {
                    // get contact by ID here
                    string str = input.Split(' ')[1]; // retrieve ID of contact from command

                    // get contact info and print in the below format
                    // ID: 1
                    // Name: James Khan
                    // Phone: 09099999999
                    // Email: [email protected]

                    int id      = Convert.ToInt32(str);
                    var contact = _contactManager.GetByID(id);

                    if (contact == null)
                    {
                        Console.WriteLine($"Contact with ID '{id}' does not exist");
                    }
                    else
                    {
                        Console.WriteLine("ID: {0}", contact.ID);
                        Console.WriteLine("Name: {0}", contact.Name);
                        Console.WriteLine("Phone: {0}", contact.PhoneNumber);
                        Console.WriteLine("Email: {0}", contact.EmailAddress);

                        // or
                        //Console.WriteLine($"ID: {contact.ID}");
                        //Console.WriteLine($"Name: {contact.Name}");
                        //Console.WriteLine($"Phone: {contact.PhoneNumber}");
                        //Console.WriteLine($"Email: {contact.EmailAddress}");
                    }
                }
                else if (input == "all")
                {
                    // get all contact and print them in the below format
                    // ID: 1, Name: James Khan, Phone: 09099999999, Email: [email protected]

                    // print here
                    var contacts = _contactManager.GetAll();

                    if (contacts == null || !contacts.Any())
                    {
                        Console.WriteLine("Contact book is empty");
                    }
                    else
                    {
                        foreach (var i in contacts)
                        {
                            Console.WriteLine("ID: {0}, Name: {1}, Phone: {2}, Email: {3}", i.ID, i.Name, i.PhoneNumber, i.EmailAddress);
                        }
                    }
                }
                else if (input.StartsWith("delete")) // e.g: get 1 (delete contact with ID=1)
                {
                    // get contact by ID here
                    string str = input.Split(' ')[1]; // retrieve ID of contact to delete
                    int    id  = Convert.ToInt32(str);

                    // delete here
                    bool result = _contactManager.Delete(id);

                    if (result == true)
                    {
                        Console.WriteLine("Contact has been deleted");
                    }
                    else
                    {
                        Console.WriteLine("Unable to delete contact details");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey();
            goto _start;
        }
 public bool Delete(long id)
 {
     contactManager = new ContactManager(ModelFactory <ContactModel> .GetContext());
     return(contactManager.Delete(id));
 }