/// <summary> /// Method returns filtered customers from databse /// </summary> /// <param name="filter">Name or Surname of Customer</param> /// <returns>Collection of Customers from Database</returns> public async Task <ObservableCollection <DtoCustomer> > GetCustomers(string filter = null) { var ret = new ObservableCollection <DtoCustomer>(); using (var data = Context) { if (!string.IsNullOrWhiteSpace(filter)) { foreach (var item in await(from item in data.Customer where item.name.Contains(filter) || item.surname.Contains(filter) || item.personalIdentityNumber.Contains(filter) select item).Take(50).ToListAsync()) { ret.Add(CustomerConverter.DataAccsessToDto(item)); } } else { foreach (var item in await(from item in data.Customer select item).Take(50).ToListAsync()) { ret.Add(CustomerConverter.DataAccsessToDto(item)); } } return(ret); } }
public void ConvertFrom_GivenACustomer_ShouldBeConvertedAsExpected() { var converter = new CustomerConverter(); var customer = converter.ConvertFrom(new CPlus.Models.Customer() { Name = "Luiz Freneda", City = "Sao Paulo", Email = "*****@*****.**", Number = "123", Street = "Rua dos Pinheiros", Phone = "11963427199", State = "SP", ZipCode = "05422010" }); customer .AssertProperties() .EnsureThat(c => c.Name).ShouldBe("Luiz Freneda") .And(c => c.City).ShouldBe("Sao Paulo") .And(c => c.Email).ShouldBe("*****@*****.**") .And(c => c.Number).ShouldBe("123") .And(c => c.Street).ShouldBe("Rua dos Pinheiros") .And(c => c.Phone).ShouldBe("11963427199") .And(c => c.State).ShouldBe("SP") .And(c => c.ZipCode).ShouldBe("05422010") .Assert(); }
public async Task <List <CustomerViewModel> > GetAllCustomerAsync( CancellationToken ct = default(CancellationToken)) { var customers = CustomerConverter.ConvertList(await _customerRepository.GetAllAsync(ct)).ToList(); return(customers); }
public CustomerDTO Modifica(string username, string field, string newValue) { Customer customer = new Customer(); customer = modelloDatiDbContext.Customers.Where(custom => custom.Username == username).FirstOrDefault(); if (field.Equals("Nome")) { customer.Nome = newValue; } else if (field.Equals("Cognome")) { customer.Cognome = newValue; } else if (field.Equals("Email")) { customer.Email = newValue; } else if (field.Equals("Username")) { customer.Username = newValue; } else if (field.Equals("Password")) { customer.Password = newValue; } modelloDatiDbContext.SaveChanges(); return(CustomerConverter.convertToDto(customer)); }
public async Task <List <CustomerViewModel> > GetCustomerBySupportRepIdAsync(int id, CancellationToken ct = default(CancellationToken)) { var customers = await _customerRepository.GetBySupportRepIdAsync(id, ct); return(CustomerConverter.ConvertList(customers).ToList()); }
public void CustomerListShouldBeLoadedFromXml() { string input = @"<customers><customer> <created-at type=""datetime"">2009-06-26T18:36:11+02:00</created-at> <id type=""integer"">52917</id> <name>Test</name> <note nil=""true""></note> <updated-at type=""datetime"">2009-06-26T18:36:11+02:00</updated-at> <archived type=""boolean"">false</archived> </customer> <customer> <created-at type=""datetime"">2009-06-26T18:36:11+02:00</created-at> <id type=""integer"">52917</id> <name>Test</name> <note nil=""true""></note> <updated-at type=""datetime"">2009-06-26T18:36:11+02:00</updated-at> <archived type=""boolean"">false</archived> </customer> </customers>"; IList<Customer> customers = new CustomerConverter().ConvertToList(input); Assert.That(customers.Count, Is.EqualTo(2)); }
public ActionResult Customers(string salespersonId) { var model = new SalespersonViewModel(); var salesperson = _salespersonDynamicsRepository.GetSalesperson(salespersonId); var customers = new List <CustomerViewModel>(); var tempCustomers = _customerDynamicsRepository.GetCustomers().Where(x => x.SLPRSNID.Replace(" ", string.Empty).ToLower() == salespersonId.Replace(" ", string.Empty).ToLower()).OrderBy(y => y.SHRTNAME).ToList(); if (tempCustomers != null && tempCustomers.Count > 0) { foreach (var tempCustomer in tempCustomers) { CustomerViewModel convertedModel = new CustomerConverter().ConvertToListView(tempCustomer); customers.Add(convertedModel); } } model.Customers = customers; model.SalespersonName = salesperson.SLPRSNFN + " " + salesperson.SPRSNSLN; return(View(model)); }
private static CustomerController CustomerPutController() { LoggingService service = new LoggingService(); CustomerRepository repository = new CustomerRepository(service); CustomerConverter converter = new CustomerConverter(); CreateCustomerUseCase useCase = new CreateCustomerUseCase(repository, converter); return(new CustomerController(useCase)); }
public CustomerDTO AssociaACustomer(int buildingID, string username) { Building b = modelloDatiDbContext.Buildings.Find(buildingID); Customer c = modelloDatiDbContext.Customers.Where(cc => cc.Username == username).FirstOrDefault(); b.Customer = c; modelloDatiDbContext.SaveChanges(); return(CustomerConverter.convertToDto(c)); }
public CustomerDTO Customer(int id) { CustomerDTO item = new CustomerConverter().Convert(facade.GetCustomerRepo().Get(id)); if (item == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return item; }
private static CustomerPutController CreateCustomerPutController() { CustomerRepository customerRepository = new CustomerRepository(); CustomerConverter customerConverter = new CustomerConverter(); CreateCustomerUseCase customerUseCase = new CreateCustomerUseCase(customerRepository, customerConverter); CustomerPutController customerController = new CustomerPutController(customerUseCase); return(customerController); }
public ActionResult Detail(string customerId) { var customer = _customerDynamicsRepository.GetCustomer(customerId); CustomerViewModel model = new CustomerConverter().ConvertToView(customer); model.CustomerAddresses = GetCustomerAddresses(customerId); return(View(model)); }
public async Task <ObservableCollection <Customer> > GetCustomers(string filter) { var ret = new ObservableCollection <Customer>(); foreach (var c in await Post <string, ObservableCollection <DtoCustomer> >("GetCustomers", filter)) { ret.Add(CustomerConverter.DtoToViewModel(c)); } return(ret); }
private static CustomerGetController CreateCustomerGetController() { LoggingService loggingService = new LoggingService(); ICustomerRepository CustomerRepository = new CustomerRepository(loggingService); FindCustomerByIdUseCase findCustomerByIdUseCase = new FindCustomerByIdUseCase(CustomerRepository); CustomerConverter customerConverter = new CustomerConverter(); CustomerGetController controller = new CustomerGetController(findCustomerByIdUseCase, customerConverter); return(controller); }
private static CustomerPutController CreateCustomerPutController() { LoggingService loggingService = new LoggingService(); ICustomerRepository CustomerRepository = new CustomerRepository(loggingService); CustomerConverter customerConverter = new CustomerConverter(); CreateCustomerUseCase createCustomerUseCase = new CreateCustomerUseCase(CustomerRepository, customerConverter); CustomerPutController controller = new CustomerPutController(createCustomerUseCase); return(controller); }
public IEnumerable <CustomerDTO> Get() { List <CustomerDTO> l = new List <CustomerDTO>(); foreach (Customer c in modelloDatiDbContext.Customers) { l.Add(CustomerConverter.convertToDto(c)); } return(l); }
public CustomerViewModel(CustomerDataService CustomerDataService) { _customerDataService = CustomerDataService; Customers = new BindableCollection <Customers>(); addCustomerCommand = new AddCustomerCommand(this); deleteCustomerCommand = new DeleteCustomerCommand(this); EditCustomerCommand = new EditCustomerCommand(this); CustomerConverter = new CustomerConverter(); Load(); }
public void Execute(object parameter) { var mainViewModel = (MainViewModel)Application.Current.Properties["mainViewModel"]; var customerConverter = new CustomerConverter(mainViewModel.SelectedItemRow); var customer = customerConverter.Convert(); CustomerDetailVm viewModel = new CustomerDetailVm(customer); CustomerDetail customerDetail = new CustomerDetail(viewModel); customerDetail.Show(); }
public void ItShouldReturnDTOFromCustomer() { CustomerId id = new CustomerId("1111"); CustomerName name = new CustomerName("customer"); Customer customer = Customer.SignUp(id, name); CustomerConverter converter = new CustomerConverter(); var actual = converter.Convert(customer); Assert.AreEqual("1111", actual.Id); Assert.AreEqual("customer", actual.Name); }
public JsonResult GetCustomer(string customerId) { var model = new CustomerViewModel(); var customer = _customerDynamicsRepository.GetCustomer(customerId); if (customer != null) { model = new CustomerConverter().ConvertToView(customer); } return(Json(model, JsonRequestBehavior.AllowGet)); }
public async Task <Result <List <Customer> > > GetCustomers() { var resultFromClient = await customersClient.GetCustomersAsync(); return(new Result <List <Customer> > { IsSuccess = resultFromClient.IsSuccess, Message = resultFromClient.Message, Value = resultFromClient.IsSuccess ? resultFromClient.Value.Select(c => CustomerConverter.FromDto(c)).ToList() : null }); }
public async Task <CustomerModel> GetCustomerAsync(string id) { if (string.IsNullOrEmpty(id)) { return(null); } var customer = await _context.Customers.SingleAsync(c => c.CustomerID == id); var model = CustomerConverter.ConvertToCustomerModel(customer); return(model); }
public int UpdateCustomers(IEnumerable <customer> items) { using (IOPContext db = new IOPContext()) { CustomerConverter converter = new CustomerConverter(db); foreach (var item in items) { var model = converter.FromDto(item); db.Entry(model).State = System.Data.Entity.EntityState.Modified; } return(db.SaveChanges()); } }
public async Task <Result <Customer> > CreateCustomer(Customer customer) { var resultFromClient = await customersClient.CreateCustomerAsync(CustomerConverter.ToDto(customer)); return(new Result <Customer> { IsSuccess = resultFromClient.IsSuccess, Message = resultFromClient.Message, Value = resultFromClient.IsSuccess ? CustomerConverter.FromDto(resultFromClient.Value) : null }); }
public IEnumerable <CustomerDTO> GetByUserRole(string userRole) { List <CustomerDTO> l = new List <CustomerDTO>(); foreach (Customer c in modelloDatiDbContext.Customers) { if (c.User_role.Equals(userRole)) { l.Add(CustomerConverter.convertToDto(c)); } } return(l); }
public async Task <CustomerViewModel> GetCustomerByIdAsync(int id, CancellationToken ct = default(CancellationToken)) { var customerViewModel = CustomerConverter.Convert(await _customerRepository.GetByIdAsync(id, ct)); customerViewModel.Invoices = await GetInvoiceByCustomerIdAsync(customerViewModel.CustomerId, ct); customerViewModel.SupportRep = await GetEmployeeByIdAsync(customerViewModel.SupportRepId.GetValueOrDefault(), ct); customerViewModel.SupportRepName = $"{customerViewModel.SupportRep.LastName}, {customerViewModel.SupportRep.FirstName}"; return(customerViewModel); }
/// <summary> /// Will get a specific Customer found by the Id /// </summary> /// <param name="id"></param> /// <returns></returns> public HttpResponseMessage Get(int id) { var customer = new Facade().GetCustomerRepository().Get(id); CustomerDto customerDto = null; if (customer != null) { customerDto = new CustomerConverter().Convert(customer); return Request.CreateResponse<CustomerDto>(HttpStatusCode.OK, customerDto); } var response = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Customer not found.") }; throw new HttpResponseException(response); }
public CustomerDTO login(string username, string password) { Customer customer = modelloDatiDbContext.Customers.Where(c => c.Username == username && c.Password == password).FirstOrDefault(); CustomerDTO customerDTO = new CustomerDTO(); if (customer != null) { customerDTO = CustomerConverter.convertToDto(customer); return(customerDTO); } else { return(null); } }
/// <summary> /// Adding or Updating Customer in a database /// </summary> /// <param name="customer">Business Object Customer</param> /// <returns>True if succeeded and false otherwise</returns> public async Task <bool> SaveCustomer(DtoCustomer customer) { try { using (var data = Context) { var c = await (from item in data.Customer where customer.Id == item.id select item).FirstOrDefaultAsync(); // Updating Customer if (c != null) { c.name = customer.Name; c.surname = customer.Surname; c.street = customer.Street; c.postalCode = customer.PostalCode; c.phoneNumber = customer.PhoneNumber; c.personalIdentityNumber = customer.PersonalIdentityNumber; c.identityCardNumber = customer.IdentityCardNumber; c.icePhoneNumber = customer.IcePhoneNumber; c.houseNumber = customer.HouseNumber; c.email = customer.Email; c.city = customer.City; c.apartmentNumber = customer.ApartmentNumber; c.password = AuthenticationLogic.HashPassword(customer.Password, customer); } // Adding new Customer else { if ( await (from item in data.Customer where customer.PersonalIdentityNumber == item.personalIdentityNumber select item).AnyAsync()) { return(false); } data.Customer.Add(CustomerConverter.DtoToDataAccess(customer)); } await data.SaveChangesAsync(); } return(true); } catch (Exception) { return(false); } }
public async Task <IActionResult> Get() { try { return(Ok( CustomerConverter.ConvertList( await _context.Customer.ToListAsync() ) )); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(500, ex.Message)); } }
public void ItShoulReturnSameDTOWhenIsTryingToConvert() { //Arrange CustomerId customerId = new CustomerId(1234); CustomerName customerName = new CustomerName("customer"); Customer customer = Customer.Create(customerId, customerName); CustomerConverter converter = new CustomerConverter(); //Act var result = converter.Convert(customer); //Assert Assert.AreEqual(result.Id, customer.Id().CustomerID); Assert.AreEqual(result.Name, customer.Name().CustomerNAME); }
/// <summary> /// Returns Custmer with specific ID /// </summary> /// <param name="customerId">Customer ID</param> /// <returns>Customer Business Object</returns> public async Task <DtoCustomer> GetCustomer(int customerId) { try { using (var data = Context) return (CustomerConverter.DataAccsessToDto( await (from item in data.Customer where item.id == customerId select item) .FirstOrDefaultAsync())); } catch (Exception) { return(null); } }
/// <summary> /// Executes the operations associated with the cmdlet. /// </summary> public override void ExecuteCmdlet() { CustomerConverter converter; Customer customer; IValidator <Address> validator; string customerId; try { customerId = (InputObject == null) ? CustomerId : InputObject.CustomerId; if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.SetPartnerCustomerWhatIf, customerId))) { if (InputObject == null && string.IsNullOrEmpty(CustomerId)) { throw new PSInvalidOperationException(Resources.InvalidSetCustomerIdentifierException); } customer = Partner.Customers[customerId].Get(); converter = new CustomerConverter(this, customer); converter.Convert(); validator = new AddressValidator(Partner); if (validator.IsValid(customer.BillingProfile.DefaultAddress)) { Partner.Customers[customerId].Profiles.Billing.Update(customer.BillingProfile); WriteObject(new PSCustomer(customer)); } else { throw new PSInvalidOperationException("The address specified was invalid. Please check the values and try again."); } } } catch (PartnerException ex) { throw new PSPartnerException("An error was encountered when communicating with Partner Center.", ex); } finally { converter = null; customer = null; } }
public void CustomerShouldBeLoadedFromXml() { string input = @"<customer> <created-at type=""datetime"">2009-06-26T18:36:11+02:00</created-at> <id type=""integer"">52917</id> <name>Test</name> <note nil=""true""></note> <updated-at type=""datetime"">2009-06-26T18:36:11+02:00</updated-at> <archived type=""boolean"">false</archived> </customer>"; Customer customer = new CustomerConverter().Convert(input); Assert.That(customer.Id, Is.EqualTo(52917)); Assert.That(customer.Archived, Is.EqualTo(false)); Assert.That(customer.Name, Is.EqualTo("Test")); }
/// <summary> /// Creates a Customer in the Database /// </summary> /// <param name="customer"></param> /// <returns></returns> public HttpResponseMessage Post(CustomerDto customerDto) { try { var customer = new CustomerConverter().Convert(customerDto); facade.GetCustomerRepository().Add(customer); var response = Request.CreateResponse<CustomerDto>(HttpStatusCode.Created, customerDto); var uri = Url.Link("GetCustomerById", new { customer.Id }); response.Headers.Location = new Uri(uri); return response; } catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent("Could not add a customer to the database") }; throw new HttpResponseException(response); } }
/// <summary> /// Updates a Customer in Database /// </summary> /// <param name="customer"></param> /// <returns></returns> public HttpResponseMessage Put(CustomerDto customerDto) { try { Customer customer = new CustomerConverter().Convert(customerDto); facade.GetCustomerRepository().Edit(customer); var response = Request.CreateResponse<CustomerDto>(HttpStatusCode.OK, customerDto); var uri = Url.Link("GetCustomerById", new { customer.Id }); response.Headers.Location = new Uri(uri); return response; } catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent("No matching customer") }; throw new HttpResponseException(response); } }
public void SetUp() { converter = new CustomerConverter(); fakeEntity = new Customer { Id = NumberFaker.Number(1, int.MaxValue), Name = StringFaker.Alpha(25), StreetAddress = new Address { Address1 = LocationFaker.Street(), Address2 = LocationFaker.Street(), City = LocationFaker.City(), State = StringFaker.Alpha(2), PostalCode = LocationFaker.PostCode(), Country = LocationFaker.Country() }, BillingAddress = new Address { Address1 = LocationFaker.Street(), Address2 = LocationFaker.Street(), City = LocationFaker.City(), State = StringFaker.Alpha(2), PostalCode = LocationFaker.PostCode(), Country = LocationFaker.Country() }, OfficePhone1 = PhoneFaker.Phone(), OfficePhone2 = PhoneFaker.Phone(), OfficeFax = PhoneFaker.Phone(), Email = InternetFaker.Email(), PrimaryContact = new HumanContact { FirstName = NameFaker.FirstName(), LastName = NameFaker.LastName(), Email = InternetFaker.Email(), Fax = PhoneFaker.Phone(), Phone1 = PhoneFaker.Phone(), Phone2 = PhoneFaker.Phone(), Notes = TextFaker.Sentence() }, Notes = TextFaker.Sentences(5) }; fakeViewModel = new CustomerViewModel { Id = NumberFaker.Number(1, int.MaxValue), Name = StringFaker.Alpha(25), CanLicensePreReleaseVersions = BooleanFaker.Boolean(), StreetAddress = new Address { Address1 = LocationFaker.Street(), Address2 = LocationFaker.Street(), City = LocationFaker.City(), State = StringFaker.Alpha(2), PostalCode = LocationFaker.PostCode(), Country = LocationFaker.Country() }, BillingMatchesStreetAddress = BooleanFaker.Boolean(), BillingAddress = new Address { Address1 = LocationFaker.Street(), Address2 = LocationFaker.Street(), City = LocationFaker.City(), State = StringFaker.Alpha(2), PostalCode = LocationFaker.PostCode(), Country = LocationFaker.Country() }, OfficePhone1 = PhoneFaker.Phone(), OfficePhone2 = PhoneFaker.Phone(), OfficeFax = PhoneFaker.Phone(), Email = InternetFaker.Email(), PrimaryContact = new HumanContact { FirstName = NameFaker.FirstName(), LastName = NameFaker.LastName(), Email = InternetFaker.Email(), Fax = PhoneFaker.Phone(), Phone1 = PhoneFaker.Phone(), Phone2 = PhoneFaker.Phone(), Notes = TextFaker.Sentence() }, Notes = TextFaker.Sentences(5) }; }