public IActionResult Add(Search search) { // Create the Customer and show the Edit page with default values var request = WebRequest.Create(_serviceSetting.URI + "customer/"); request.Method = "POST"; request.ContentType = "text/json"; using (var stream = request.GetRequestStream()) { var customer = new Customer { Name = search.Query, Gender = "", HouseNumber = 1, AddressLine1 = "", State = "", Country = "", Category = "", DateOfBirth = new DateTime() }; using (StreamWriter sw = new StreamWriter(stream)) sw.Write(JsonConvert.SerializeObject(customer)); } using (var response = request.GetResponse()) { var loc = response.Headers["Location"]; return RedirectToAction("Edit", new { id = loc.Substring(loc.LastIndexOf('/') + 1) }); } }
public static void AddCustomer(Customer customer) { var connectionString = ConfigurationManager.ConnectionStrings["appDatabase"].ConnectionString; using (var connection = new SqlConnection(connectionString)) { var command = new SqlCommand { Connection = connection, CommandType = CommandType.StoredProcedure, CommandText = "uspAddCustomer" }; var firstNameParameter = new SqlParameter("@Firstname", SqlDbType.VarChar, 50) { Value = customer.Firstname }; command.Parameters.Add(firstNameParameter); var surnameParameter = new SqlParameter("@Surname", SqlDbType.VarChar, 50) { Value = customer.Surname }; command.Parameters.Add(surnameParameter); var dateOfBirthParameter = new SqlParameter("@DateOfBirth", SqlDbType.DateTime) { Value = customer.DateOfBirth }; command.Parameters.Add(dateOfBirthParameter); var emailAddressParameter = new SqlParameter("@EmailAddress", SqlDbType.VarChar, 50) { Value = customer.EmailAddress }; command.Parameters.Add(emailAddressParameter); var hasCreditLimitParameter = new SqlParameter("@HasCreditLimit", SqlDbType.Bit) { Value = customer.HasCreditLimit }; command.Parameters.Add(hasCreditLimitParameter); var creditLimitParameter = new SqlParameter("@CreditLimit", SqlDbType.Int) { Value = customer.CreditLimit }; command.Parameters.Add(creditLimitParameter); var companyIdParameter = new SqlParameter("@CompanyId", SqlDbType.Int) { Value = customer.Company.Id }; command.Parameters.Add(companyIdParameter); connection.Open(); command.ExecuteNonQuery(); } }
public void InsertCustomer(Entities.Customer objCustomer) { using (var model = new NorthwindModelEntities()) { model.Customers.Add(objCustomer); model.SaveChanges(); } }
internal void MergeNodes(Customer customer) { var query = _graphClient.Cypher.Merge(string.Format("(p: Customer {{ Id: {0}, Name: '{1}', HouseNumber: {2}, DateOfBirth: '{3}'}})", customer.Id, customer.Name, customer.HouseNumber, customer.DateOfBirth.ToString("yyyy-MM-dd"))) .Merge(string.Format("(g: Gender {{ Name: '{0}'}})", customer.Gender)) .Merge(string.Format("(a: Address {{ Name: '{0}'}})", customer.AddressLine1)) .Merge(string.Format("(s: State {{ Name: '{0}'}})", customer.State)) .Merge(string.Format("(c: Country {{ Name: '{0}'}})", customer.Country)) .Merge(string.Format("(cat: Category {{ Name: '{0}'}})", customer.Category)); query.ExecuteWithoutResults(); }
public void UpdateCustomer(Entities.Customer objCustomer) { using (var model = new NorthwindModelEntities()) { var original = model.Customers.Find(objCustomer.CustomerID); if (original != null) { model.Entry(original).CurrentValues.SetValues(objCustomer); model.SaveChanges(); } } }
public void Should_map_many_to_one_association() { Customer customer; using(var ctx = DataContextFactory()) { customer = new Customer(); ctx.GetTable<Customer>().InsertOnSubmit(customer); ctx.SubmitChanges(); } using(var test = Verify<Order>()) { test.TestProperty(x => x.OrderDate, new DateTime(2008, 12, 23)); test.TestProperty(x => x.Customer, customer); } }
public bool AddCustomer(string firstName, string surName, string email, DateTime dateOfBirth, int companyId) { if (!ValidateInput(firstName, surName, email, dateOfBirth)) return false; var company = _companyRepository.GetById(companyId); if (company == null) return false; //Todo: create a new company var customer = new Customer { Company = company, DateOfBirth = dateOfBirth, EmailAddress = email, Firstname = firstName, Surname = surName }; switch (company.Name.ToLower()) { case "veryimportantclient": customer.HasCreditLimit = false; break; case "importantclient": customer.HasCreditLimit = true; using (var customerCreditService = new CustomerCreditServiceClient()) { var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth); creditLimit = creditLimit * 2; customer.CreditLimit = creditLimit; } break; default: customer.HasCreditLimit = true; using (var customerCreditService = new CustomerCreditServiceClient()) { var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth); customer.CreditLimit = creditLimit; } break; } if (customer.HasCreditLimit && customer.CreditLimit < 500) { return false; } CustomerDataAccess.AddCustomer(customer); return true; }
internal void CreateRelationships(Customer customer) { var query = _graphClient.Cypher.Match(string.Format("(p: Customer {{ Id: {0}, Name: '{1}', HouseNumber: {2}, DateOfBirth: '{3}'}})", customer.Id, customer.Name, customer.HouseNumber, customer.DateOfBirth.ToString("yyyy-MM-dd"))) .Match(string.Format("(g: Gender {{ Name: '{0}'}})", customer.Gender)) .Match(string.Format("(a: Address {{ Name: '{0}'}})", customer.AddressLine1)) .Match(string.Format("(s: State {{ Name: '{0}'}})", customer.State)) .Match(string.Format("(c: Country {{ Name: '{0}'}})", customer.Country)) .Match(string.Format("(cat: Category {{ Name: '{0}'}})", customer.Category)) .Merge("(p)-[:IS_GENDER]->(g)") .Merge("(p)-[:LIVES_ON_ADDRESS]->(a)") .Merge("(p)-[:LIVES_IN_STATE]->(s)") .Merge("(p)-[:LIVES_IN_COUNTRY]->(c)") .Merge("(p)-[:IS_CATEGORY]->(cat)"); query.ExecuteWithoutResults(); }
public IActionResult Delete(Customer customer) { if (customer.Id == 0) { var referer = Context.Request.Headers["Referer"]; customer.Id = int.Parse(referer.Substring(referer.LastIndexOf('/') + 1)); } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_serviceSetting.URI + "customer/" + customer.Id); request.Method = "DELETE"; using (var response = request.GetResponse()) { } return RedirectToAction("Search"); }
public bool SearchCustomer(string id) { con = new SqlConnection(Connection); cmd = new SqlCommand(); cmd.CommandText = string.Format("Select * from profile where Userid='{0}'", id); cmd.Connection = con; con.Open(); cmd.Connection = con; cmd.ExecuteNonQuery(); reader = cmd.ExecuteReader(); if (reader.Read()) { if (string.IsNullOrWhiteSpace(reader[6].ToString()) && string.IsNullOrWhiteSpace(reader[5].ToString())) { if (reader[7].ToString() == "Dealer") { return(false); } customer = new Customer(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString(), reader[7].ToString(), 0, 0, reader[8].ToString()); //start from here... //start from here. } else if (string.IsNullOrWhiteSpace(reader[6].ToString())) { if (reader[7].ToString() == "Dealer") { return(false); } customer = new Customer(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString(), reader[7].ToString(), Double.Parse(reader[5].ToString()), 0, reader[8].ToString()); //start from here... //start from here. } else if (string.IsNullOrWhiteSpace(reader[5].ToString())) { if (reader[7].ToString() == "Dealer") { return(false); } customer = new Customer(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString(), reader[7].ToString(), 0, Double.Parse(reader[6].ToString()), reader[8].ToString()); //start from here... //start from here. } else { if (reader[7].ToString() == "Dealer") { return(false); } customer = new Customer(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString(), reader[7].ToString(), Double.Parse(reader[5].ToString()), Double.Parse(reader[6].ToString()), reader[8].ToString()); //start from here... } con.Close(); return(true); } else { con.Close(); return(false); } }
protected override void Update(Customer customer) { throw new NotImplementedException(); }
protected override void Update(Customer customer) => _databaseConnection.Update(customer);
protected override void Add(Customer customer) => _databaseConnection.Insert(customer);
public IActionResult Save(Customer customer) { if (customer.Id == 0) { var referer = Context.Request.Headers["Referer"]; customer.Id = int.Parse(referer.Substring(referer.LastIndexOf('/') + 1)); } var request = WebRequest.Create(_serviceSetting.URI + "customer/"); request.ContentType = "text/json"; request.Method = "PUT"; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(JsonConvert.SerializeObject(customer)); } using (var response = request.GetResponse()) { var loc = response.Headers["Location"]; return RedirectToAction("Edit", new { id = loc.Substring(loc.LastIndexOf('/') + 1) }); } }
protected void SaveData(Customer customer) => _database.OnSave(customer);
protected abstract void Update(Customer customer);
public bool Validate(Customer customer) => !string.IsNullOrWhiteSpace(customer.FirstName) && !string.IsNullOrWhiteSpace(customer.LastName) && Connection.IsValidEmailAddress(customer.Email) && !string.IsNullOrWhiteSpace(customer.Phone) && !string.IsNullOrWhiteSpace(customer.Email);
protected abstract void Add(Customer customer);
protected override void Add(Customer customer) => _customers.Add(customer);
void InitializeCustomer() => _customer = new Customer() { FirstName = FirstName, LastName = LastName, Phone = Phone, Email = Email };
string UpdateHeaderAsync(string headerTemplate, Statement statement, Customer customer, string logo) { var headerBlock = new StringBuilder(headerTemplate); var profile = statement.Profile; var address = statement.Address; headerBlock = headerBlock.Replace("~HEADER_LOGO~", logo); headerBlock = headerBlock.Replace("~TITLE~", statement.TypeName); headerBlock = headerBlock.Replace("~PROVIDE_COMPANY_NAME~", profile.BusinessName); headerBlock = headerBlock.Replace("~PROVIDER_STREET_ADDRESS1~", profile.Address1); headerBlock = headerBlock.Replace("~PROVIDER_STREET_ADDRESS2~", profile.Address2); headerBlock = headerBlock.Replace("~PROVIDER_CITY_STATE_ZIP~", profile.Postal); headerBlock = headerBlock.Replace("~PROVIDER_PHONE~", profile.Phone); headerBlock = headerBlock.Replace("~PROVIDER_EMAIL~", profile.Email); headerBlock = headerBlock.Replace("Comments", statement.Title); ProcessAppDifferences(statement, headerBlock); headerBlock = headerBlock.Replace("~STATEMENT_NUMBER~", statement.StatementNumber.ToString()); headerBlock = headerBlock.Replace("~STATEMENT_FOR~", string.Format("{0} for", statement.TypeName)); try { //SQLiteAsyncConnection connection = new SQLiteAsyncConnection(Bizmonger.Client.Infrastructure.Constants.DATABASE_FILE_NAME); //var customerId = statement.CustomerId.ToString(); //var customerQuery = connection.Table<Bizmonger.Client.Infrastructure.DAL.Entities.Customer>(). // Where(c => c.CustomerId == customerId); //var customer = await customerQuery.FirstOrDefaultAsync(); headerBlock = headerBlock.Replace("~CLIENT_NAME~", string.Format("{0} {1}", customer.FirstName, customer.LastName)); headerBlock = headerBlock.Replace("~CLIENT_EMAIL~", customer.Email); headerBlock = headerBlock.Replace("~CLIENT_PHONE~", customer.Phone); } catch (Exception ex) { Debug.WriteLine($"Failed to query customer data:{ex.Message}"); } return headerBlock.ToString(); }
public string ApplyHeaderAsync(string quoteTemplate, Statement statement, Customer customer, string logo) { var headerTemplate = UpdateHeaderAsync(quoteTemplate, statement, customer, logo); return quoteTemplate.Replace(quoteTemplate, headerTemplate); }