/// <summary> /// Add the new contact information to the database /// </summary> /// <param name="contactDetailsModel"></param> /// <returns>int</returns> public int AddContact(ContactDO item) { int rowsAffected = 0; OleDbConnection connection = new OleDbConnection(connectionString); try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"Insert Into TBL_Contact([First Name], [Last Name], [Email Address], [Phone Number], [Status])VALUES('" + item.FirstName.Trim() + "', '" + item.LastName.Trim() + "', '" + item.EmailID.Trim() + "', '" + item.PhoneNumber.Trim() + "', " + true + ");"; cmd.Connection = connection; connection.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { connection.Close(); } return(rowsAffected); }
/// <summary> /// Insert contact. /// </summary> /// <param name="contact">Contact to be inserted</param> public int InsertContact(ContactDO contact) { contact.Id = Contacts.Select(c => c.Id).Max() + 1; Contacts.Add(contact); CommitChangesToFile(); return(contact.Id); }
/// <summary> /// Fetch Contact information for particular contact Id /// </summary> /// <param name="id"></param> /// <returns>ContactDO</returns> public ContactDO GetContact(int id) { ContactDO contactDetails = new ContactDO(); OleDbConnection connection = new OleDbConnection(connectionString); try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"SELECT * FROM TBL_Contact WHERE [Status] = True AND [Contact ID] = " + id; cmd.Connection = connection; connection.Open(); OleDbDataAdapter ada = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); ada.Fill(ds); GetContactDO(contactDetails, ds); } catch (Exception ex) { throw ex; } finally { connection.Close(); } return(contactDetails); }
/// <summary> /// Updates the existing contact information /// </summary> /// <param name="contactDetailsModel"></param> /// <returns>int</returns> public int UpdateContact(ContactDO item) { int rowsAffected = 0; OleDbConnection connection = new OleDbConnection(connectionString); try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"UPDATE TBL_Contact SET [First Name] = '" + item.FirstName.Trim() + "', [Last Name] = '" + item.LastName.Trim() + "', [Email Address] = '" + item.EmailID.Trim() + "', [Phone Number] = '" + item.PhoneNumber.Trim() + "' WHERE [Contact ID] = " + item.ContactId; cmd.Connection = connection; connection.Open(); rowsAffected = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { connection.Close(); } return(rowsAffected); }
/// <summary> /// Maps the data set columns to the properties of Contact DO model to get the contact information /// </summary> /// <param name="contactDetails"></param> /// <param name="ds"></param> private void GetContactDO(ContactDO contactDetails, DataSet ds) { contactDetails.ContactId = Convert.ToInt32(ds.Tables[0].Rows[0]["Contact ID"].ToString()); contactDetails.FirstName = ds.Tables[0].Rows[0]["First Name"].ToString(); contactDetails.LastName = ds.Tables[0].Rows[0]["Last Name"].ToString(); contactDetails.EmailID = ds.Tables[0].Rows[0]["Email Address"].ToString(); contactDetails.PhoneNumber = ds.Tables[0].Rows[0]["Phone Number"].ToString(); contactDetails.Status = Convert.ToBoolean(ds.Tables[0].Rows[0]["Status"].ToString()); }
/// <summary> /// Updates the existing contact information /// </summary> /// <param name="contactDetailsModel"></param> /// <returns>int</returns> public int UpdateContact(ContactModel contactDetailsModel) { ContactDO contactDetailsDO = Mapper.Mapper.MapToContactDO(contactDetailsModel); if (!CheckIfContactAlreadyExist(contactDetailsDO)) { return(2); //2 for contact is not exist in DB } return(_iContacts.UpdateContact(contactDetailsDO)); }
/// <summary> /// Add the new contact information to the database /// </summary> /// <param name="contactDetailsModel"></param> /// <returns>int</returns> public int AddContact(ContactModel contactDetailsModel) { ContactDO contactDetailsDO = Mapper.Mapper.MapToContactDO(contactDetailsModel); if (CheckIfContactAlreadyExist(contactDetailsDO)) { return(2); //2 for contact is already exist in DB } return(_iContacts.AddContact(contactDetailsDO)); }
/// <summary> /// Maps the Contact DO model in the Data Access with the Contact Model in Business Access /// </summary> /// <param name="contactDetailsDO"></param> /// <returns>ContactModel</returns> public static ContactModel MapToContactModel(ContactDO contactDetailsDO) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <ContactDO, ContactModel>(); }); IMapper iMapper = config.CreateMapper(); ContactModel contactDetailsModel = iMapper.Map <ContactDO, ContactModel>(contactDetailsDO); return(contactDetailsModel); }
/// <summary> /// Update contact /// </summary> /// <param name="contact">Contact to be updated</param> public void UpdateContact(ContactDO contact) { var contactToUpdate = Contacts.FirstOrDefault(c => c.Id == contact.Id); if (contactToUpdate == null) { return; } int index = Contacts.IndexOf(contactToUpdate); Contacts.RemoveAt(index); Contacts.Insert(index, contact); CommitChangesToFile(); }
/// <summary> /// Maps the data set columns to the properties of Contact DO model to get the list of contacts /// </summary> /// <param name="contactList"></param> /// <param name="ds"></param> private void GetContactDOList(List <ContactDO> contactList, DataSet ds) { foreach (DataRow row in ds.Tables[0].Rows) { ContactDO contactDetails = new ContactDO(); contactDetails.ContactId = Convert.ToInt32(row["Contact ID"].ToString()); contactDetails.FirstName = row["First Name"].ToString(); contactDetails.LastName = row["Last Name"].ToString(); contactDetails.EmailID = row["Email Address"].ToString(); contactDetails.PhoneNumber = row["Phone Number"].ToString(); contactDetails.Status = Convert.ToBoolean(row["Status"].ToString()); contactList.Add(contactDetails); } }
public static ContactBO FromDOToBO(ContactDO contactDO) { if (contactDO == null) { return(null); } return(new ContactBO { Id = contactDO.Id, FirstName = contactDO.FirstName, LastName = contactDO.LastName, PhoneNumber = contactDO.PhoneNumber, Email = contactDO.Email, Status = contactDO.IsActive ? Constants.Active : Constants.Inactive }); }
/// <summary> /// To check if contact is already exists or not /// </summary> /// <param name="item"></param> /// <returns>bool</returns> public bool CheckIfContactAlreadyExist(ContactDO item) { bool isContactExist = false; OleDbConnection connection = new OleDbConnection(connectionString); try { OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"SELECT * FROM TBL_Contact WHERE [Status] = True AND [First Name] = '" + item.FirstName.Trim() + "' AND [Last Name] = '" + item.LastName.Trim() + "'"; cmd.Connection = connection; connection.Open(); OleDbDataAdapter ada = new OleDbDataAdapter(cmd); DataSet ds = new DataSet(); ada.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { isContactExist = true; } else { isContactExist = false; } } catch (Exception ex) { throw ex; } finally { connection.Close(); } return(isContactExist); }
/// <summary> /// Checks if contact is already exists or not /// </summary> /// <param name="contactDetailsDO"></param> /// <returns></returns> private bool CheckIfContactAlreadyExist(ContactDO contactDetailsDO) { return(_iContacts.CheckIfContactAlreadyExist(contactDetailsDO)); }
/// <summary> /// Fetch Contact information for particular contact Id /// </summary> /// <param name="id"></param> /// <returns>ContactModel</returns> public ContactModel GetContact(int id) { ContactDO contactDetailsDO = _iContacts.GetContact(id); return(Mapper.Mapper.MapToContactModel(contactDetailsDO)); }
public void UpdateContact(ContactDO contact) { throw new NotImplementedException(); }
public int InsertContact(ContactDO contact) { throw new NotImplementedException(); }