public ActionResult CreateNewContact(Contact newContact) { DbConnection conn = new DbConnection(); conn.SqlCommand.Connection.Open(); ContactLogic logic = new ContactLogic(); int contactID = -1; try { contactID = logic.CreateNewContact(conn, newContact.Name, newContact.Surname, newContact.Phone, newContact.Email); newContact.Id = contactID; } catch (Exception e) { ViewData["Message"] = ErrorMessages.CreateNewContact; return(View("Messages")); } finally { conn.SqlCommand.Connection.Close(); } return(View("EditContact", newContact)); }
public ContactFacade(IServiceProvider serviceProvider, DealTrackingDbContext dbContext) { this.DbContext = dbContext; this.DbSet = this.DbContext.Set <Contact>(); this.IdentityService = serviceProvider.GetService <IdentityService>(); this.ContactLogic = serviceProvider.GetService <ContactLogic>(); }
public ActionResult Contacts(int currentPage = 1, string orderBy = "id", string order = "asc", string searchBy = "name", string searchByValue = "") { DbConnection conn = new DbConnection(); conn.SqlCommand.Connection.Open(); ContactLogic contactlogic = new ContactLogic(); int numberOfContacts = contactlogic.GetTotalNumberOfContacts(conn, searchBy, searchByValue); conn.SqlCommand.Parameters.Clear(); searchByValue = searchByValue == "undefined" ? "" : searchByValue; searchBy = searchBy == "undefined" ? "name" : searchBy; conn.Reader = contactlogic.GetListOfContactsWithPagination(conn, currentPage, orderBy, order, searchBy, searchByValue); ContactsViewModel listOfContacts = new ContactsViewModel { Contacts = contactlogic.GenerateListOfContactsFromSqlDataReader(conn.Reader), NumberOfPaginationPages = contactlogic.GenerateNumberOfPaginationPagesFromTotalNumberOfContacts(currentPage, numberOfContacts), CurrentPage = currentPage, CurrentOrder = order, OrderBy = orderBy, TotalNumberOfContacts = numberOfContacts, SearchBy = searchBy, SearchByValue = searchByValue }; conn.SqlCommand.Connection.Close(); return(View(listOfContacts)); }
protected BaseController() { Logger = LogManager.GetLogger(GetType()); Database = new OpaContext(); PersonHelper = new PersonLogic(Database); UserHelper = new UserLogic(Database, PersonHelper); PaymentHelper = new PaymentLogic(Database, PersonHelper); ContactHelper = new ContactLogic(Database); FinancialHelper = new FinancialLogic(Database); }
public async Task <IHttpActionResult> SaveContact([FromBody] Contact contact) { try { //save contact from http request body ContactLogic contactLogic = new ContactLogic(); var email = await contactLogic.SaveContacts(contact); return(Ok(email)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public ActionResult DeleteContact(int contactID) { DbConnection conn = new DbConnection(); conn.SqlCommand.Connection.Open(); ContactLogic contactlogic = new ContactLogic(); bool success = contactlogic.DeleteContact(conn, contactID); if (success) { ViewData["Message"] = ErrorMessages.DeleteContact_Success; } else { ViewData["Message"] = ErrorMessages.DeleteContact_Error; } conn.SqlCommand.Connection.Close(); return(View("Messages")); }
public ActionResult EditContact(Contact editedContact) { DbConnection conn = new DbConnection(); conn.SqlCommand.Connection.Open(); ContactLogic contactlogic = new ContactLogic(); bool success = contactlogic.UpdateContact(conn, editedContact.Name, editedContact.Surname, editedContact.Phone, editedContact.Email, editedContact.Id); if (success) { ViewData["Message"] = ErrorMessages.EditContact_Success; } else { ViewData["Message"] = ErrorMessages.EditContact_Error; } conn.SqlCommand.Connection.Close(); return(View("Messages")); }
public ActionResult EditContact(int contactID) { DbConnection conn = new DbConnection(); conn.SqlCommand.Connection.Open(); ContactLogic contactlogic = new ContactLogic(); conn.Reader = contactlogic.GetContactByID(conn, contactID); if (!conn.Reader.HasRows) { ViewData["Message"] = String.Format("Contact with ID {0} does not exist", contactID); return(View("Messages")); } Contact contact = contactlogic.GetContactFromSqlDataReader(conn.Reader); conn.SqlCommand.Connection.Close(); return(View(contact)); }
public ContactsController() { _contactLogic = new ContactLogic(); }