/// <summary> /// Takes a datamodel customer and turns it into a store customer. /// </summary> /// <param name="DbCustomer">A data model customer to be added to the model</param> /// <returns>A Model customer</returns> public static Store.Customer MapCustomerToStore(DataModel.Customer DbCustomer) { if (DbCustomer != null) { Name name = Db_StoreMapper.getCustomerName(DbCustomer); if (Customers.Instance.HasCustomer(name)) { //something weird happened probably. Expecting customers to be gotten from //the model first before checking DB. Console.Error.WriteLine($"Warning: Customer {name} already existed in the model"); return(Customers.Instance.GetCustomer(name)); } else { if (DbCustomer.StoreLocation != null) { return(Customers.Instance.RegisterCustomer(name, Locations.Instance.GetOrRegisterLocation(DbCustomer.StoreLocation))); } return(Customers.Instance.RegisterCustomer(name, DbCustomer.StoreLocation)); } } else { return(null); } }
/// <summary> /// These three functions perform very similarly, they take an object from the Library /// and convert it into a single record in the table /// </summary> public void AddCustomer(Customer customer) { using var context = new StoredbContext(_contextOptions); var new_customer = new DataModel.Customer { FirstName = customer.FirstName, LastName = customer.LastName }; context.Customers.Add(new_customer); context.SaveChanges(); }
public void AddToCustomerDb(Library.Customer customer) { using var context = new AquariumContext(_contextOptions); var newCust = new DataModel.Customer() { FirstName = customer.FirstName, LastName = customer.LastName, Email = customer.Email }; context.Customers.Add(newCust); context.SaveChanges(); }
private PersistCustomer CreateSystemUnderTest(DataModel.Customer entity, out CrmContext context) { context = new CrmContext( new DbContextOptionsBuilder <CrmContext>() .UseInMemoryDatabase("db") .Options); var mapper = new Mock <IMapper>(); mapper.Setup(s => s.Map <DataModel.Customer>(It.IsAny <AddCustomer>())).Returns(entity); return(new PersistCustomer(context, mapper.Object)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); // KWD added to return the account numbers and log the transaction BusinessProcess.ProfileManager profileManager = new BusinessProcess.ProfileManager(); DataModel.Customer customer = await profileManager.RequestCustomerProfile(model.Email); BusinessProcess.IDValidationManager validationManager = new BusinessProcess.IDValidationManager(); if (customer != null) { model.Address = customer.address; model.accounts = customer.Accounts; switch (result) { case SignInStatus.Success: validationManager.LogTransaction(customer.customerID, "Success"); return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: validationManager.LogTransaction(customer.customerID, "Lockout"); return(View("Lockout")); case SignInStatus.RequiresVerification: validationManager.LogTransaction(customer.customerID, "SendCode"); return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: validationManager.LogTransaction(customer.customerID, "Invalid"); ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } } else { validationManager.LogTransaction(0, "Invalid"); ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
/// <summary> /// An Add Customer method. /// </summary> /// <param name="customer"> Passing in a customer already defined </param> public void AddCustomer(Library.Customer customer) { using var context = new StoreDBContext(_contextOptions); // pass in all the values of customer and place them in. DataModel.Customer newCustomer = new DataModel.Customer() { FirstName = customer.FirstName, LastName = customer.LastName, Email = customer.Email, Phone = customer.Phone }; // add customer to context context.Add(newCustomer); context.SaveChanges(); }
public async Task Customer_IsSavedToDbContext() { var entity = new DataModel.Customer { Name = "test customer" }; IRequestHandler <AddCustomer, Unit> systemUnderTest = CreateSystemUnderTest(entity, out var context); var request = new AddCustomer { Name = "test customer" }; await systemUnderTest.Handle(request, CancellationToken.None); Assert.Contains(context.Customers, c => c.Name == "test customer"); }
public static CustomerUpdate FromCustomer(DataModel.Customer customer) { Metadata metadata = null; if (customer.Metadata != null) { metadata = new Metadata(); foreach (var key in customer.Metadata.Keys) { metadata.Add(key, customer.Metadata[key]); } } return(new CustomerUpdate() { Name = customer.Name, Email = customer.Email, Description = customer.Description, Metadata = metadata }); }
public async static Task Run(Voucherify.Api api) { try { DataModel.Customer createdCustomer = await api.Customers.Create( new DataModel.Contexts.CustomerCreate() { Email = "*****@*****.**", Metadata = new Core.DataModel.Metadata(new Dictionary <string, object>() { { "key1", "value1" }, { "key2", "value2" } }), Description = "Test Description", Name = "Bandro" }); Console.WriteLine("[CustomerFlow] (Create) Result: {0}", createdCustomer); DataModel.Customer getCustomer = await api.Customers.Get(createdCustomer.Id); Console.WriteLine("[CustomerFlow] (Get) Result: {0}", getCustomer); DataModel.Customer updatedCustomer = await api.Customers.Update( getCustomer.Id, DataModel.Contexts.CustomerUpdate.FromCustomer(getCustomer) .WithDescription("Test Description Updated") .WithName("Bandro Updated")); Console.WriteLine("[CustomerFlow] (Update) Result: {0}", updatedCustomer); await api.Customers.Delete(updatedCustomer.Id); Console.WriteLine("[CustomerFlow] (Delete) Done"); } catch (Exception e) { Console.WriteLine("[CustomerFlow] Exception: {0}", e); } }
public int UpdateCustomerConfiguration(Customer Customer) { if (!BusinessRule.CheckConfigurationCount(Customer)) { throw new ConfigurationCountLimitExceededException("1 configuration set should not have more than 3 configurations!"); } if (!BusinessRule.CheckConfigurationType(Customer)) { throw new DuplicatedConfigurationTypeException("1 configuration set should not have 2 or more configurations that are of the same type!"); } Dictionary <string, string> suspectConfs = null; if (!BusinessRule.CheckConfigurationDBConnectionString(Customer, out suspectConfs)) { throw new DuplicatedDatabaseException("1 configuration set should not have 2 or more configurations that are using the same database!"); } else if ((suspectConfs != null) && (suspectConfs.Count > 0)) { string message = "Suspect databases found in the bindings of the following configurations, please double check to make sure that they are not the same database:"; string suspectConfListTemplate = "Business Name: \"{0}\", Server Name: \"{1}\"; "; message += System.Environment.NewLine; foreach (string bizName in suspectConfs.Keys) { message += string.Format(suspectConfListTemplate, bizName, suspectConfs[bizName]); message += System.Environment.NewLine; } throw new DuplicatedDatabaseException(message); } if (!BusinessRule.ValidateConfigurationDBConnectionString(Customer)) { throw new InvalidConnectionStringException("Connection string is invalid! Make sure each field of the connection string has its value assigned, and also make sure loopback address is not used."); } int returnValue = -9; using (DataModel.DataModelContainer container = new DataModelContainer()) { DataModel.Customer cust = container.Customers.First((o) => (o.Id.ToLower() == Customer.ID.ToLower())); cust.Name = Customer.Name; //cust.ReferenceId = Customer.ReferenceID; if (Customer.ReferenceID != null) { cust.ReferenceId = ""; for (int i = 0; i < Customer.ReferenceID.Length; i++) { cust.ReferenceId += Customer.ReferenceID[i]; if (i != (Customer.ReferenceID.Length - 1)) { cust.ReferenceId += ","; } } } var confs = container.Configurations.Where((o) => (o.CustomerId == Customer.ID)).ToArray(); List <Configuration> customerConfList = new List <Configuration>(Customer.Configurations); for (int i = 0; i < confs.Length; i++) { for (int j = 0; j < customerConfList.Count; j++) { if ((confs[i] != null) && (customerConfList[j] != null)) { if (confs[i].Id.ToLower() == customerConfList[j].ID.ToLower()) { confs[i].DbConnectionString = customerConfList[j].DbConnectionString; confs[i].TypeId = ((int)(customerConfList[j].ConfigurationType)); customerConfList.RemoveAt(j); j--; } } } } if (customerConfList.Count > 0) { foreach (var conf in customerConfList) { if (conf != null) { DataModel.Configuration configuration = new DataModel.Configuration() { Customer = cust, Id = conf.ID, CustomerId = cust.Id, DbConnectionString = conf.DbConnectionString, TypeId = (int)(conf.ConfigurationType) }; container.Configurations.Add(configuration); } } } returnValue = container.SaveChanges(); } return(returnValue); }
public string AddCustomerConfiguration(Customer Customer) { if (!BusinessRule.CheckConfigurationCount(Customer)) { throw new ConfigurationCountLimitExceededException("1 configuration set should not have more than 3 configurations!"); } if (!BusinessRule.CheckConfigurationType(Customer)) { throw new DuplicatedConfigurationTypeException("1 configuration set should not have 2 or more configurations that are of the same type!"); } Dictionary <string, string> suspectConfs = null; if (!BusinessRule.CheckConfigurationDBConnectionString(Customer, out suspectConfs)) { throw new DuplicatedDatabaseException("1 configuration set should not have 2 or more configurations that are using the same database!"); } else if ((suspectConfs != null) && (suspectConfs.Count > 0)) { string message = "Suspect databases found in the bindings of the following configurations, please double check to make sure that they are not the same database:"; string suspectConfListTemplate = "Business Name: \"{0}\", Server Name: \"{1}\"; "; message += System.Environment.NewLine; foreach (string bizName in suspectConfs.Keys) { message += string.Format(suspectConfListTemplate, bizName, suspectConfs[bizName]); message += System.Environment.NewLine; } throw new DuplicatedDatabaseException(message); } if (!BusinessRule.ValidateConfigurationDBConnectionString(Customer)) { throw new InvalidConnectionStringException("Connection string is invalid! Make sure each field of the connection string has its value assigned, and also make sure loopback address is not used."); } using (DataModelContainer container = new DataModelContainer()) { DataModel.Customer cust = new DataModel.Customer() { Id = Customer.ID, Name = Customer.Name }; //if (String.IsNullOrEmpty(Customer.ReferenceID)) //{ // cust.ReferenceId = Customer.ReferenceID; //} if (Customer.ReferenceID != null) { cust.ReferenceId = ""; for (int i = 0; i < Customer.ReferenceID.Length; i++) { cust.ReferenceId += Customer.ReferenceID[i]; if (i != (Customer.ReferenceID.Length - 1)) { cust.ReferenceId += ","; } } } container.Customers.Add(cust); foreach (var conf in Customer.Configurations) { if (conf != null) { DataModel.Configuration configuration = new DataModel.Configuration() { Customer = cust, Id = conf.ID, CustomerId = cust.Id, DbConnectionString = conf.DbConnectionString, TypeId = (int)(conf.ConfigurationType) }; container.Configurations.Add(configuration); } } container.SaveChanges(); } return(Customer.ID); }
/// <summary> /// Get the Name object for the model based on the DB Customer object. /// </summary> /// <param name="c">A DB customer.</param> /// <returns>A Name struct representing the customer name</returns> public static Name getCustomerName(DataModel.Customer c) { return(new Name(c.FirstName, c.LastName, c.MiddleInitial?[0])); }