static void Main(string[] args) { //Console.WriteLine("Hello World!"); //using(var context = new StudentDBContext()) //{ // var std = new Student() // { // ID = 1, // Name = "Ram" // }; // context.Students.Add(std); // context.SaveChanges(); //} IContactRepository contactRepository = new ContactRepository(); contactRepository.AddContact( new Contact() { Name = "Ram Krishnan", EmailID = "*****@*****.**", PhoneNumber = "1234567890", NickName = "Ram" } ); contactRepository.AddContact( new Contact() { Name = "Sivakumar", EmailID = "*****@*****.**", PhoneNumber = "9987654321", NickName = "Siva" } ); contactRepository.AddContact( new Contact() { Name = "Preetha", EmailID = "*****@*****.**", PhoneNumber = "1111111111", NickName = "Preetha" } ); List <Contact> contacts = contactRepository.GetAllContacts().ToList(); Contact contact = contactRepository.GetContactByID(2); contact.PhoneNumber = "555555555"; contactRepository.UpdateContact(contact); contact = contactRepository.GetContactByID(2); contactRepository.DeleteContact(2); Console.ReadLine(); }
private void submitBtn_Click(object sender, EventArgs e) { var name = nameTxtBox.Text; var surname = surnameTxtBox.Text; var email = emailTxtBox.Text; var description = descriptionTxtBox.Text; var birth = birthPicker.Value; var age = _util.CalculateAge(birth, DateTime.Now); if (name == String.Empty || name is string == false) { MessageBox.Show(@"First name is a mandatory field"); } else if (surname == String.Empty || surname is string == false) { MessageBox.Show(@"Last Name is a mandatory field"); } else if (age == 0) { MessageBox.Show(@"You can't be 0 years old !"); } else { var contactToAdd = new Contact(name, surname, email, description, birth, age); MessageBox.Show(contactToAdd.ToString()); _contactRepository.AddContact(contactToAdd); } }
private static void AddContact(ContactRepository repository) { string name, addr; long mob; Console.Write("Enter name ==> "); name = Console.ReadLine(); Console.Write("Enter Mobile Number ==> "); mob = long.Parse(Console.ReadLine()); Contact c = new Contact { Name = name, MobileNumber = mob }; Console.Write("How many address you want to insert ==> "); int no = int.Parse(Console.ReadLine()); for (int i = 1; i <= no; i++) { Console.Write("Enter Address " + i + " ==> "); addr = Console.ReadLine(); c.Addresses.Add(new Address { City = addr }); } repository.AddContact(c); Console.WriteLine("Contact added successfully..."); }
private void _checkInfoForRecurringEvent(RecurringEvent recurringEvent) { if (string.IsNullOrWhiteSpace(TxtEventName.Text)) { MessageBox.Show("Please enter EVENT NAME", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } recurringEvent.Name = TxtEventName.Text; recurringEvent.Location = TxtLocation.Text; recurringEvent.Type = CmbType.Text; recurringEvent.Note = TxtNote.Text; recurringEvent.EventDate = DPickerDate.Value; recurringEvent.UserId = UserSession.UserData.Id; recurringEvent.Status = CmbStatus.Text; Contact selectedContact = (Contact)CmbContact.SelectedItem; if (selectedContact == null) { if (string.IsNullOrWhiteSpace(CmbContact.Text)) { recurringEvent.ContactId = 0; } else { ContactRepository contactRepository = new ContactRepository(); recurringEvent.ContactId = contactRepository.AddContact(new Contact { Name = CmbContact.Text, UserId = UserSession.UserData.Id }); } } else { recurringEvent.ContactId = selectedContact.Id; } if (ChkEndingStatus.Checked) { recurringEvent.EventEndDate = DateTime.MinValue; } else { recurringEvent.EventEndDate = DPickerEndDate.Value; } if (recurringEvent.Id > 0) { _updateEventInDatabase(recurringEvent); } else { _addEventToDatabase(recurringEvent); } }
private async void BtnContactAction_Click(object sender, EventArgs e) { string contactName = TxtContactName.Text; ContactRepository contactRepository = new ContactRepository(); MessageStatus messageStatus = new MessageStatus(); if (string.IsNullOrWhiteSpace(contactName)) { MessageBox.Show("Please enter CONTACT NAME", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Contact tempContact = contactRepository.GetContactFromName(contactName); if (tempContact.Id > 0) { MessageBox.Show("CONTACT Already Exists", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int id; _contact.Name = contactName; BtnContactAction.Enabled = false; _contact.UserId = UserSession.UserData.Id; if (_contact.Id > 0) { id = await Task.Run(() => contactRepository.UpdateContact(_contact)); } else { id = await Task.Run(() => contactRepository.AddContact(_contact)); } if (id > 0) { if (id == 1) { MessageBox.Show("Contact Updated Successfully", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Dispose(); } else { MessageBox.Show("Contact Added Successfully", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Dispose(); } } else { DialogResult result = MessageBox.Show("An Error Occured", "ERROR", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (result == DialogResult.Cancel) { this.Dispose(); } } }
public void AddContact_Throws_On_Null_Contact() { //Arrange var repository = new ContactRepository(); //Act //Assert Assert.Throws <ArgumentNullException>(() => repository.AddContact(null)); }
public void AddContact_Throws_On_Null_Contact() { //Arrange var repository = new ContactRepository(); //Act //Assert Assert.Throws<ArgumentNullException>(() => repository.AddContact(null)); }
public async Task <ActionResult <ApiResponse <Contact> > > AddContact(Contact contact) { var response = await _repository.AddContact(contact); if (response.Errors != null) { return(BadRequest(response)); } return(CreatedAtAction(nameof(GetByEmail), new { email = contact.Email }, response.Data)); }
public void AddContact_Throws_On_InValid_PortalId() { //Arrange var repository = new ContactRepository(); var contact = new Contact { PortalId = PORTAL_InValidId }; //Act //Assert Assert.Throws<ArgumentOutOfRangeException>(() => repository.AddContact(contact)); }
private void AddNewContact(object obj) { bool contactExist = false; if (ContactList.Any()) { if (ContactList[SelectedContactIndexList].FirstName == ContactFirstName && ContactList[SelectedContactIndexList].LastName == ContactLastName) { contactExist = true; } } if (!contactExist) { Contact contact = new Contact(); if (ContactTelephoneNumber != 0) { Telephone newTelephone = new Telephone { Number = ContactTelephoneNumber, Operator = ContactPhoneOperator, Type = ContactPhoneType }; contact.Telephones = new List <Telephone>(); contact.Telephones.Add(newTelephone); ContactTelephpones.Add(newTelephone); } if (!string.IsNullOrEmpty(ContactAddressStreet)) { Address address = new Address { City = ContactAddressCity, PostCode = ContactPostCode, Street = ContactAddressStreet }; contact.Address = new Address(); contact.Address = address; } contact.FirstName = ContactFirstName; contact.LastName = ContactLastName; _contactRepository.AddContact(contact); ContactList.Add(contact); GetContactDetails(); GetTelephoneDetails(); GetNumberofObjectsInDatabase(); } }
/// <summary> /// Adds a new contact to the database and cache /// </summary> /// <param name="contact"></param> /// <returns></returns> public int AddContact(Contact contact) { var contactRepository = new ContactRepository(); contactRepository.AddContact(contact); var newId = contact.Id; // add new contact to cache cache.StringSet(newId.ToString(), JsonConvert.SerializeObject(contact)); return(newId); }
public void AddContact_Throws_On_InValid_PortalId() { //Arrange var repository = new ContactRepository(); var contact = new Contact { PortalId = PORTAL_InValidId }; //Act //Assert Assert.Throws <ArgumentOutOfRangeException>(() => repository.AddContact(contact)); }
private void _checkInfoForTransaction(Transaction transaction) { if (string.IsNullOrWhiteSpace(TxtTransactionName.Text)) { MessageBox.Show("Please enter TRANSACTION NAME", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (NumUpDownAmount.Value <= 0) { MessageBox.Show("Please enter AMOUNT", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } transaction.Name = TxtTransactionName.Text; transaction.Amount = Convert.ToDouble(NumUpDownAmount.Text); transaction.Type = CmbType.Text; transaction.Note = TxtNote.Text; transaction.TransactionDate = DPickerDate.Value; transaction.UserId = UserSession.UserData.Id; Contact selectedContact = (Contact)CmbContact.SelectedItem; if (selectedContact == null) { if (string.IsNullOrWhiteSpace(CmbContact.Text)) { transaction.ContactId = 0; } else { ContactRepository contactRepository = new ContactRepository(); transaction.ContactId = contactRepository.AddContact(new Contact { Name = CmbContact.Text, UserId = UserSession.UserData.Id }); } } else { transaction.ContactId = selectedContact.Id; } if (transaction.Id > 0) { _updateTransactionInDatabase(transaction); } else { _addTransactionToDatabase(transaction); } }
private void CustomerForm_Load(object sender, EventArgs e) { if (AddContact) { var Customer = customerRep.GetCustomerById(customerid); txtCustormerName.Text = Customer.customer_name; txtLatitude.Text = Customer.latitude.ToString(); txtLongitude.Text = Customer.longitude.ToString(); if (txtContactName.Text != "") { tblContact contact = new tblContact() { contact_name = txtContactName.Text, contact_email = txtContactEmail.Text, contact_number = txtContactNumber.Text, customer_id = customerid }; contactRep.AddContact(contact); } } }
public void AddContact_Calls_IRepository_Insert_On_Valid_Contact() { //Arrange var portalId = PORTAL_ValidId; var repository = new ContactRepository(); var contact = new Contact { PortalId = portalId }; //Act repository.AddContact(contact); //Assert _mockRepository.Verify(r => r.Insert(contact)); }
public void AddContact_Calls_IRepository_Insert_On_Valid_Contact() { //Arrange var portalId = PORTAL_ValidId; var repository = new ContactRepository(); var contact = new Contact { PortalId = portalId }; //Act repository.AddContact(contact); //Assert _mockRepository.Verify(r => r.Insert(contact)); }
private static void AddContact(ContactRepository repository) { string fname, lname; long mob; Console.Write("Enter First name ==> "); fname = Console.ReadLine(); Console.Write("Enter Last name ==> "); lname = Console.ReadLine(); Console.Write("Enter Mobile Number ==> "); mob = long.Parse(Console.ReadLine()); repository.AddContact(new Contact { FirstName = fname, LastName = lname, MobileNumber = mob }); Console.WriteLine("Contact added successfully...\n"); }
// POST api/values public HttpResponseMessage Post([FromBody] Contact contact) { try { ContactRepository contactRepository = new ContactRepository(); contactRepository.AddContact(contact); var message = Request.CreateResponse(HttpStatusCode.Created, contact); message.Headers.Location = new Uri(Request.RequestUri + contact.ID.ToString()); return(message); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public void CanAddContact() { Contact contact = new Contact() { Name = "Aniket", Email = "*****@*****.**", Phone = "7722322322", Message = "Howdy Howdy Bowdy" }; var repo = new ContactRepository(); repo.AddContact(contact); // Now check in the DB if the record was added }
/* * Add Event */ private void _checkInfoForEvent(Event eventInfo) { if (string.IsNullOrWhiteSpace(TxtEventName.Text)) { MessageBox.Show("Please enter EVENT NAME", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } eventInfo.Name = TxtEventName.Text; eventInfo.Location = TxtLocation.Text; eventInfo.Type = CmbType.Text; eventInfo.Note = TxtNote.Text; eventInfo.EventDate = DPickerDate.Value; eventInfo.UserId = UserSession.UserData.Id; Contact selectedContact = (Contact)CmbContact.SelectedItem; if (selectedContact == null) { if (string.IsNullOrWhiteSpace(CmbContact.Text)) { eventInfo.ContactId = 0; } else { ContactRepository contactRepository = new ContactRepository(); eventInfo.ContactId = contactRepository.AddContact(new Contact { Name = CmbContact.Text, UserId = UserSession.UserData.Id }); } } else { eventInfo.ContactId = selectedContact.Id; } if (eventInfo.Id > 0) { _updateEventInDatabase(eventInfo); } else { _addEventToDatabase(eventInfo); } }
public void AddContact() { var repo = new ContactRepository(ConnectionString); var newContact = new ContactDataModel { UserId = 4, ContactId = 1, LastUpdateTime = DateTime.Parse("2020-05-18 16:25") }; repo.AddContact(newContact); var contact = repo.GetUserContact(4, 1); Assert.True( contact.UserId == newContact.UserId && contact.ContactId == newContact.ContactId && contact.LastUpdateTime == newContact.LastUpdateTime); }
public void AddContact_Returns_ValidId_On_Valid_Contact() { //Arrange var portalId = PORTAL_ValidId; _mockRepository.Setup(r => r.Insert(It.IsAny <Contact>())) .Callback((Contact ct) => ct.ContactId = CONTACT_ValidId); var repository = new ContactRepository(); var contact = new Contact { PortalId = portalId }; //Act int contactId = repository.AddContact(contact); //Assert Assert.AreEqual(CONTACT_ValidId, contactId); }
public int AddContact(Contact contact) { contactRepository.AddContact(contact); return(contact.Id); }
private async void ActionClick(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbx_name.Text)) { MessageBox.Show(Strings.ContactNameWrong, Strings.Error); return; } if (tbx_name.Text.Length > 100) { MessageBox.Show(Strings.ContactNameMaxLengthError, Strings.Error); return; } contact.Name = tbx_name.Text; ContactRepository contactRepository = ContactRepository.Instance; btn_action.Enabled = false; int i = contact.ID > 0 ? await Task.Run(() => contactRepository.EditContact(contact)) : await Task.Run(() => contactRepository.AddContact(contact)); string messageText = i > 0 ? (contact.ID > 0) ? Strings.EditContactOkay : Strings.AddContactOkay : Strings.SomethingError; string captionText = i > 0 ? Strings.Success : Strings.Error; MessageBox.Show(messageText, captionText); Dispose(); }
public void AddContact_Returns_ValidId_On_Valid_Contact() { //Arrange var portalId = PORTAL_ValidId; _mockRepository.Setup(r => r.Insert(It.IsAny<Contact>())) .Callback((Contact ct) => ct.ContactId = CONTACT_ValidId); var repository = new ContactRepository(); var contact = new Contact { PortalId = portalId }; //Act int contactId = repository.AddContact(contact); //Assert Assert.AreEqual(CONTACT_ValidId, contactId); }
public void AddContact(Contact newContact) { _contactRepository.AddContact(newContact); }
private async void AddTransaction() { if (tbx_name.Text.Equals("")) { MessageBox.Show(Strings.ErrorEmptyName, Strings.Error); return; } TransactionRepository transactionRepository = TransactionRepository.Instance; transaction.Name = tbx_name.Text; transaction.TypeName = cbx_type.Text; transaction.Amount = nud_amount.Value; transaction.CreatedDate = dtp_date.Value; transaction.Note = rtbx_note.Text; transaction.Type = transaction.TypeName.Equals("Income") ? true : false; Contact contact = (Contact)cbx_contact.SelectedItem; if (contact == null) { if (string.IsNullOrWhiteSpace(cbx_contact.Text)) { transaction.ContactID = 0; } else { ContactRepository contactRepository = ContactRepository.Instance; transaction.ContactID = contactRepository.AddContact(new Contact { Name = cbx_contact.Text, UserID = Instances.User.ID }); } } else { transaction.ContactID = contact.ID; } if (chbx_recurring.Checked && transaction.ID == 0) { RecurringTransaction temporaryRecurringTransaction = new RecurringTransaction { Name = transaction.Name, Amount = transaction.Amount, UserID = transaction.UserID, Type = transaction.Type, CreatedDate = transaction.CreatedDate, Note = transaction.Note, ContactID = transaction.ContactID }; if (chbx_infinite.Checked) { temporaryRecurringTransaction.EndDate = DateTime.MinValue; } else { temporaryRecurringTransaction.EndDate = dtp_end_date.Value; } temporaryRecurringTransaction.Status = cbx_frequency.Text; RecurringTransactionRepository recurringTransactionRepository = RecurringTransactionRepository.Instance; bool i = await Task.Run(() => recurringTransactionRepository.AddTransaction(temporaryRecurringTransaction)); if (i == false) { MessageBox.Show(Strings.SomethingError, Strings.Error); return; } } bool result = false; if (transaction.ID > 0) { result = await Task.Run(() => transactionRepository.EditTransaction(transaction)); } else { result = await Task.Run(() => transactionRepository.AddTransaction(transaction)); } if (transaction.ID > 0 && result) { MessageBox.Show(Strings.EditTransactionOkay, Strings.Success); Dispose(); } else if (result) { MessageBox.Show(Strings.AddTransactionOkay, Strings.Success); Dispose(); } else { MessageBox.Show(Strings.SomethingError, Strings.Error); } }
public Contact Post(Contact value) { Contact contact = _contacts.AddContact(value); return(contact); }
public void AddContact(Contact objContact) { _contactRepo.AddContact(objContact); }
/// <summary> /// Add contact to db /// </summary> /// <param name="value"></param> public void Post(Contact vm) { var r = new ContactRepository(() => new ContactsContext()); r.AddContact(vm); }
public void AddContact(Contact contact) { repository.AddContact(contact); }
public override Task <ContactModel> CreateNewContact(ContactModel request, ServerCallContext context) { ContactModel response = repository.AddContact(request); return(Task.FromResult(response)); }
private async void UpdateRecurringEvent() { if (tbx_name.Text.Equals("")) { MessageBox.Show(Strings.ErrorEmptyName); return; } RecurringEventRepository eventRepository = RecurringEventRepository.Instance; temporaryRecurringEvent.Name = tbx_name.Text; temporaryRecurringEvent.TypeName = cbx_type.Text; temporaryRecurringEvent.Location = tbx_location.Text; temporaryRecurringEvent.CreatedDate = dtp_date.Value; temporaryRecurringEvent.Note = rtbx_note.Text; RecurringEvent recurringEvent = new RecurringEvent(); recurringEvent.Status = cbx_frequency.Text; recurringEvent.EndDate = dtp_enddate.Value; if (temporaryRecurringEvent.TypeName.Equals("Task")) { temporaryRecurringEvent.Type = false; } else { temporaryRecurringEvent.Type = true; } Contact contact = (Contact)cbx_contact.SelectedItem; if (contact == null) { if (string.IsNullOrWhiteSpace(cbx_contact.Text)) { temporaryRecurringEvent.ContactID = 0; } else { ContactRepository contactRepository = ContactRepository.Instance; temporaryRecurringEvent.ContactID = await Task.Run(() => contactRepository.AddContact(new Contact { Name = cbx_contact.Text, UserID = Instances.User.ID })); } } else { temporaryRecurringEvent.ContactID = contact.ID; } if (chbx_infinite.Checked) { temporaryRecurringEvent.EndDate = DateTime.MinValue; } else { temporaryRecurringEvent.EndDate = dtp_enddate.Value; } temporaryRecurringEvent.Status = cbx_frequency.Text; bool result = false; result = await Task.Run(() => eventRepository.EditRecurringEvent(temporaryRecurringEvent)); if (temporaryRecurringEvent.ID > 0 && result) { MessageBox.Show(Strings.EditRecurringEventOkay, Strings.Success); Dispose(); } else { MessageBox.Show(Strings.SomethingError, Strings.Error); } }