public void TestDeleteCustomer()
        {
            //Anlegen des Customers
            CustomerPoco customerPoco = new CustomerPoco
            {
                Birthday    = DateTime.Parse("2018/06/24"),
                Firstname   = "Philipp",
                Lastname    = "Mustermanntest",
                Gender      = "männlich",
                Housenumber = 24,
                Street      = "Marktplatz",
                ZipCode     = 4310,
                Town        = "Mauthausen"
            };

            //Einfügen
            this.rentalController.CreateNewCustomer(customerPoco);

            BikeContext context  = new BikeContext();
            Customer    customer = context.Customers.Last();

            //Löschen
            this.rentalController.DeleteCustomer(customer.CustomerId);

            //Selektiern
            Customer selectCustomer = this.rentalController.GetAllCustomers(customerPoco.Lastname).Find(c => c.CustomerId == customer.CustomerId);

            //Nachschauen
            if (selectCustomer != null)
            {
                Assert.Fail();
            }
        }
예제 #2
0
        public async Task <IActionResult> GetCustomer(string userid)
        {
            CustomerPoco customer = await _service.GetCustomerByUsername(userid);

            if (customer == null)
            {
                return(BadRequest("Customer has not registered yet"));
            }
            return(Ok(customer));
        }
예제 #3
0
 public Customer(CustomerPoco customerPoco)
 {
     this.Birthday    = customerPoco.Birthday;
     this.CustomerId  = customerPoco.CustomerId;
     this.Firstname   = customerPoco.Firstname;
     this.Gender      = customerPoco.Gender;
     this.Housenumber = customerPoco.Housenumber;
     this.Lastname    = customerPoco.Lastname;
     this.Street      = customerPoco.Street;
     this.Town        = customerPoco.Town;
     this.ZipCode     = customerPoco.ZipCode;
 }
예제 #4
0
        private void ProcessCustomers(FileStream stream)
        {
            foreach (var xCustomer in GetXElements(stream, "Customer"))
            {
                var customer = new CustomerPoco
                {
                    Email               = xCustomer.Get("Email"),
                    FirstName           = xCustomer.Get("FirstName"),
                    LastName            = xCustomer.Get("LastName"),
                    Roles               = xCustomer.GetEnumerable("Roles", ','),
                    ShowInDemoUserMenu  = xCustomer.GetIntOrDefault("ShowInDemoUserMenu", 1),
                    DemoUserTitle       = xCustomer.Get("DemoUserTitle"),
                    Location            = xCustomer.Get("Location"),
                    DemoUserDescription = xCustomer.Get("DemoUserDescription"),
                    DemoSortOrder       = xCustomer.GetIntOrDefault("DemoSort"),
                    Addresses           = new List <AddressPoco>(),
                    CreditCards         = new List <CreditCardPoco>()
                };

                foreach (var xAddress in xCustomer.Element("Addresses")?.Elements("Address") ?? Enumerable.Empty <XElement>())
                {
                    var address = new AddressPoco
                    {
                        Name        = xAddress.Get("Name"),
                        Line1       = xAddress.Get("Line1"),
                        City        = xAddress.Get("City"),
                        CountryCode = xAddress.Get("CountryCode"),
                        CountryName = xAddress.Get("CountryName"),
                        RegionCode  = xAddress.Get("RegionCode"),
                        RegionName  = xAddress.Get("RegionName"),
                        PostalCode  = xAddress.Get("PostalCode")
                    };

                    customer.Addresses.Add(address);
                }

                foreach (var xCreditCard in xCustomer.Element("CreditCards")?.Elements("CreditCard") ?? Enumerable.Empty <XElement>())
                {
                    var cc = new CreditCardPoco
                    {
                        Number          = xCreditCard.Get("Number"),
                        CardType        = xCreditCard.Get("CardType"),
                        LastFour        = xCreditCard.Get("LastFour"),
                        ExpirationYear  = xCreditCard.GetInt("ExpirationYear"),
                        ExpirationMonth = xCreditCard.GetInt("ExpirationMonth")
                    };

                    customer.CreditCards.Add(cc);
                }

                SaveCustomer(customer, PrimaryKeyId.Empty);
            }
        }
        public void TestCreateRental()
        {
            BikePoco bikePoco = new BikePoco
            {
                Brand               = "KTM",
                Category            = "Sport Bike",
                DateOfLastService   = DateTime.Parse("2018/01/20"),
                PriceFirstHour      = 3,
                PriceAdditionalHour = 5,
                PurchaseDate        = DateTime.Now
            };

            this.rentalController.CreateNewBike(bikePoco);

            CustomerPoco customerPoco = new CustomerPoco
            {
                Birthday    = DateTime.Parse("2018/06/24"),
                Firstname   = "Philipp",
                Lastname    = "CreateCustomerTest",
                Gender      = "männlich",
                Housenumber = 24,
                Street      = "Marktplatz",
                ZipCode     = 4310,
                Town        = "Mauthausen"
            };

            this.rentalController.CreateNewCustomer(customerPoco);

            BikeContext context = new BikeContext();

            Bike     bike     = context.Bikes.Last();
            Customer customer = context.Customers.Last();
            Rental   rental   = new Rental
            {
                Bike        = bike,
                Customer    = customer,
                Paid        = false,
                RentalBegin = DateTime.Parse("24.06.1999 10:00:00"),
                RentalEnd   = DateTime.Parse("24.06.1999 11:00:00"),
                TotalPrice  = 0
            };

            context.Add(rental);
            context.SaveChanges();

            Rental selectRental = this.rentalController.GetAllRentalsByCustomerId(customer.CustomerId).Find(r => r.Customer.CustomerId == customer.CustomerId);

            if (selectRental == null)
            {
                Assert.Fail();
            }
        }
예제 #6
0
        public void UpdateCustomer(CustomerPoco customer)
        {
            var oldCustomer = this.rentalDataAccess.GetCustomerById(customer.CustomerId);

            if (oldCustomer != null)
            {
                this.rentalDataAccess.UpdateCustomer(oldCustomer, customer);
            }
            else
            {
                throw new Exception("Customer does not exist!");
            }
        }
        public async Task <IActionResult> Edit(CustomerPoco customer)
        {
            if (ModelState.IsValid)
            {
                var _customer = _mapper.Map <Customer>(customer);
                _customer.ModifiedOn = DateTime.Now;
                _unitOfWork.CustomerRepository.Update(_customer);
                _unitOfWork.AddressRepository.Update(customer.Address);
                await _unitOfWork.SaveAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.Titles  = new SelectList(await _unitOfWork.TitleRepository.Get(), "TitleId", "TitleName", customer.TitleId);
            ViewBag.Doctors = new SelectList(await _unitOfWork.DoctorRepository.Get(), "DoctorId", "Surname", customer.DoctorId);
            return(View(customer));
        }
예제 #8
0
        public async Task <IActionResult> PostCustomer([FromBody] CustomerPoco customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                customer = await _service.RegisterCustomer(customer);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(customer));
        }
예제 #9
0
        private static void MapAddressesFromCustomerToContact(CustomerPoco customer, CustomerContact contact)
        {
            foreach (var importedAddress in customer.Addresses)
            {
                var address = CustomerAddress.CreateInstance();

                address.Name        = importedAddress.Name;
                address.City        = importedAddress.City;
                address.CountryCode = importedAddress.CountryCode;
                address.CountryName = importedAddress.CountryName;
                address.FirstName   = customer.FirstName;
                address.LastName    = customer.LastName;
                address.Line1       = importedAddress.Line1;
                address.RegionCode  = importedAddress.RegionCode;
                address.RegionName  = importedAddress.RegionName;
                address.AddressType = CustomerAddressTypeEnum.Public | CustomerAddressTypeEnum.Shipping | CustomerAddressTypeEnum.Billing;

                contact.AddContactAddress(address);
            }
        }
예제 #10
0
        public async Task PostCustomer_Test()
        {
            var customer = new CustomerPoco()
            {
                CustomerId = Guid.NewGuid()
            };
            // Arrange
            var mockService = new Mock <ICustomersService>();

            mockService.Setup(x => x.RegisterCustomer(customer));

            // Arrange
            var controller = new CustomersController(mockService.Object);

            // Act
            IActionResult actionResult = await controller.PostCustomer(customer);

            var contentResult = actionResult as OkResult;

            // Assert
            Assert.NotNull(contentResult);
        }
예제 #11
0
        public async Task GetFavourites_test()
        {
            var customerID = Guid.NewGuid();
            var customer   = new CustomerPoco()
            {
                CustomerId = customerID
            };

            // Arrange
            var mockFavouriteskService = new Mock <IFavouritesService>();

            mockFavouriteskService.Setup(x => x.GetFavouriteDrugs(customerID))
            .Returns(Task.FromResult <IEnumerable <DrugPoco> >(new List <DrugPoco> {
                new DrugPoco()
                {
                    DrugName = "drug1"
                },
                new DrugPoco()
                {
                    DrugName = "drug2"
                }
            }));

            var mockCustomersService = new Mock <ICustomersService>();

            mockCustomersService.Setup(x => x.GetCustomer(customerID))
            .Returns(Task.FromResult(customer));

            // Arrange
            var controller = new FavouritesController(mockFavouriteskService.Object, mockCustomersService.Object);

            // Act
            var favourites = await controller.Get();

            // Assert
            Assert.NotNull(favourites);
            //Assert.Equal(2, favourites.Count());
        }
        public void TestCreateNewCustomer()
        {
            CustomerPoco customer = new CustomerPoco
            {
                Birthday    = DateTime.Parse("2018/06/24"),
                Firstname   = "Philipp",
                Lastname    = "CreateCustomerTest",
                Gender      = "männlich",
                Housenumber = 24,
                Street      = "Marktplatz",
                ZipCode     = 4310,
                Town        = "Mauthausen"
            };

            this.rentalController.CreateNewCustomer(customer);

            Customer selectCustomer = this.rentalController.GetAllCustomers(customer.Lastname).Find(c => c.Lastname == customer.Lastname);

            if (selectCustomer == null)
            {
                Assert.Fail();
            }
        }
예제 #13
0
        public async Task <IActionResult> PutCustomer(Guid id, CustomerPoco customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerId)
            {
                return(BadRequest());
            }

            try
            {
                await _service.UpdateCustomerDetails(customer);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok(customer));
        }
예제 #14
0
        public async Task GetDrugs_Test()
        {
            var drugName   = "viagra";
            var customerID = Guid.NewGuid();
            var customer   = new CustomerPoco()
            {
                CustomerId = customerID
            };
            // Arrange
            var mockDrugService = new Mock <IDrugsService>();

            mockDrugService.Setup(x => x.GetDrugs(customerID, drugName))
            .Returns(Task.FromResult <IEnumerable <DrugPoco> >(new List <DrugPoco>()
            {
                new DrugPoco()
                {
                    DrugName = "viagra"
                }
            }));

            var mockCustomersService = new Mock <ICustomersService>();

            mockCustomersService.Setup(x => x.GetCustomer(customerID))
            .Returns(Task.FromResult(customer));


            // Arrange
            var controller = new DrugsController(mockDrugService.Object, mockCustomersService.Object);

            // Act
            var drugs = await controller.GetDrugs(drugName);


            // Assert
            Assert.NotNull(drugs);
            //Assert.Single(drugs);
        }
예제 #15
0
 public CustomerPoco PocoInPocoOut(CustomerPoco data)
 {
     return(new CustomerPoco(data.Data));
 }
예제 #16
0
        public void CreateNewCustomer(CustomerPoco newPocoCustomer)
        {
            Customer newCustomer = new Customer(newPocoCustomer);

            this.rentalDataAccess.CreateNewCustomer(newCustomer);
        }
예제 #17
0
        private void SaveCustomer(CustomerPoco customer, PrimaryKeyId orgId)
        {
            var user = _userManager.FindByEmailAsync(customer.Email)
                       .GetAwaiter()
                       .GetResult();

            if (user == null)
            {
                user = new SiteUser
                {
                    CreationDate = DateTime.UtcNow,
                    Username     = customer.Email,
                    Email        = customer.Email,
                    FirstName    = customer.FirstName,
                    LastName     = customer.LastName,
                    IsApproved   = true
                };

                var result = _userManager.CreateAsync(user, "Episerver123!")
                             .GetAwaiter()
                             .GetResult();

                if (!result.Succeeded)
                {
                    return;
                }
            }

            foreach (var role in customer.Roles)
            {
                if (!_roleManager.RoleExistsAsync(role)
                    .GetAwaiter()
                    .GetResult())
                {
                    var createdRole = new IdentityRole(role);

                    var roleResult = _roleManager.CreateAsync(createdRole)
                                     .GetAwaiter()
                                     .GetResult();

                    if (!roleResult.Succeeded)
                    {
                        continue;
                    }
                    _userManager.AddToRoleAsync(user.Id, role)
                    .GetAwaiter()
                    .GetResult();
                }
            }

            FoundationContact foundationContact;
            var contact = CustomerContext.GetContactByUserId($"String:{customer.Email}");

            if (contact == null)
            {
                foundationContact        = FoundationContact.New();
                foundationContact.UserId = customer.Email;
                foundationContact.Email  = customer.Email;
            }
            else
            {
                foundationContact = new FoundationContact(contact);
            }

            foundationContact.FirstName            = customer.FirstName;
            foundationContact.LastName             = customer.LastName;
            foundationContact.FullName             = $"{foundationContact.FirstName} {foundationContact.LastName}";
            foundationContact.RegistrationSource   = "Imported customer";
            foundationContact.AcceptMarketingEmail = true;
            foundationContact.ConsentUpdated       = DateTime.UtcNow;
            foundationContact.UserRole             = customer.B2BRole;
            foundationContact.UserLocationId       = customer.Location;
            foundationContact.DemoUserTitle        = customer.DemoUserTitle;
            foundationContact.DemoUserDescription  = customer.DemoUserDescription;
            foundationContact.ShowInDemoUserMenu   = customer.ShowInDemoUserMenu == 0 ? 1 : customer.ShowInDemoUserMenu;
            foundationContact.DemoSortOrder        = customer.DemoSortOrder;

            if (orgId != PrimaryKeyId.Empty)
            {
                foundationContact.Contact.OwnerId = orgId;
            }
            foundationContact.SaveChanges();

            MapAddressesFromCustomerToContact(customer, foundationContact.Contact);
            MapCreditCardsFromCustomerToContact(customer.CreditCards, foundationContact.Contact);
            foundationContact.SaveChanges();
        }
예제 #18
0
        private void ProcessOrganizations(FileStream stream)
        {
            foreach (var xOrganization in GetXElements(stream, "Organization"))
            {
                var organization = new OrganizationPoco
                {
                    Id               = xOrganization.Get("Id"),
                    Name             = xOrganization.Get("Name"),
                    Users            = new List <CustomerPoco>(),
                    CreditCards      = new List <CreditCardPoco>(),
                    SubOrganizations = new List <OrganizationPoco>()
                };

                foreach (var xUser in xOrganization.Element("Users")?.Elements("User") ?? Enumerable.Empty <XElement>())
                {
                    var customer = new CustomerPoco
                    {
                        Email               = xUser.Get("Email"),
                        FirstName           = xUser.Get("FirstName"),
                        LastName            = xUser.Get("LastName"),
                        Roles               = xUser.GetEnumerable("Roles", ','),
                        B2BRole             = xUser.Get("B2BRole"),
                        Location            = xUser.Get("Location"),
                        ShowInDemoUserMenu  = xUser.GetIntOrDefault("ShowInDemoUserMenu", 1),
                        DemoUserTitle       = xUser.Get("DemoUserTitle"),
                        DemoUserDescription = xUser.Get("DemoUserDescription"),
                        DemoSortOrder       = xUser.GetIntOrDefault("DemoSort"),
                        Addresses           = new List <AddressPoco>(),
                        CreditCards         = new List <CreditCardPoco>()
                    };

                    foreach (var xAddress in xUser.Element("Addresses")?.Elements("Address") ?? Enumerable.Empty <XElement>())
                    {
                        var address = new AddressPoco
                        {
                            Name        = xAddress.Get("Name"),
                            Line1       = xAddress.Get("Line1"),
                            City        = xAddress.Get("City"),
                            CountryCode = xAddress.Get("CountryCode"),
                            CountryName = xAddress.Get("CountryName"),
                            RegionCode  = xAddress.Get("RegionCode"),
                            RegionName  = xAddress.Get("RegionName"),
                            PostalCode  = xAddress.Get("PostalCode")
                        };

                        customer.Addresses.Add(address);
                    }

                    organization.Users.Add(customer);
                }

                foreach (var xCreditCard in xOrganization.Element("CreditCards")?.Elements("CreditCard") ?? Enumerable.Empty <XElement>())
                {
                    var cc = new CreditCardPoco
                    {
                        Number          = xCreditCard.Get("Number"),
                        CardType        = xCreditCard.Get("CardType"),
                        LastFour        = xCreditCard.Get("LastFour"),
                        ExpirationYear  = xCreditCard.GetInt("ExpirationYear"),
                        ExpirationMonth = xCreditCard.GetInt("ExpirationMonth")
                    };

                    organization.CreditCards.Add(cc);
                }

                foreach (var xSubOrganization in xOrganization.Element("SubOrganizations")?.Elements("SubOrganization") ?? Enumerable.Empty <XElement>())
                {
                    var subOrganization = new OrganizationPoco
                    {
                        Id               = xSubOrganization.Get("Id"),
                        Name             = xSubOrganization.Get("Name"),
                        Users            = new List <CustomerPoco>(),
                        CreditCards      = new List <CreditCardPoco>(),
                        SubOrganizations = new List <OrganizationPoco>()
                    };

                    foreach (var xUser in xSubOrganization.Element("Users")?.Elements("User") ?? Enumerable.Empty <XElement>())
                    {
                        var customer = new CustomerPoco
                        {
                            Email               = xUser.Get("Email"),
                            FirstName           = xUser.Get("FirstName"),
                            LastName            = xUser.Get("LastName"),
                            Roles               = xUser.GetEnumerable("Roles", ','),
                            B2BRole             = xUser.Get("B2BRole"),
                            Location            = xUser.Get("Location"),
                            ShowInDemoUserMenu  = xUser.GetIntOrDefault("ShowInDemoUserMenu", 1),
                            DemoUserTitle       = xUser.Get("DemoUserTitle"),
                            DemoUserDescription = xUser.Get("DemoUserDescription"),
                            DemoSortOrder       = xUser.GetIntOrDefault("DemoSort"),
                            Addresses           = new List <AddressPoco>(),
                            CreditCards         = new List <CreditCardPoco>()
                        };

                        foreach (var xAddress in xUser.Element("Addresses")?.Elements("Address") ?? Enumerable.Empty <XElement>())
                        {
                            var address = new AddressPoco
                            {
                                Name        = xAddress.Get("Name"),
                                Line1       = xAddress.Get("Line1"),
                                City        = xAddress.Get("City"),
                                CountryCode = xAddress.Get("CountryCode"),
                                CountryName = xAddress.Get("CountryName"),
                                RegionCode  = xAddress.Get("RegionCode"),
                                RegionName  = xAddress.Get("RegionName"),
                                PostalCode  = xAddress.Get("PostalCode")
                            };

                            customer.Addresses.Add(address);
                        }

                        subOrganization.Users.Add(customer);
                    }

                    foreach (var xCreditCard in xSubOrganization.Element("CreditCards")?.Elements("CreditCard") ?? Enumerable.Empty <XElement>())
                    {
                        var cc = new CreditCardPoco
                        {
                            Number          = xCreditCard.Get("Number"),
                            CardType        = xCreditCard.Get("CardType"),
                            LastFour        = xCreditCard.Get("LastFour"),
                            ExpirationYear  = xCreditCard.GetInt("ExpirationYear"),
                            ExpirationMonth = xCreditCard.GetInt("ExpirationMonth")
                        };

                        subOrganization.CreditCards.Add(cc);
                    }

                    organization.SubOrganizations.Add(subOrganization);
                }

                SaveOrganization(organization);
            }
        }
예제 #19
0
 //Update
 public void UpdateCustomer(Customer oldCustomer, CustomerPoco customer)
 {
     this.bikeContext.Entry(oldCustomer).CurrentValues.SetValues(customer);
     this.bikeContext.SaveChanges();
 }
 public void UpdateCustomer([FromBody] CustomerPoco customer)
 {
     this.rentalBusinessLogic.UpdateCustomer(customer);
 }
 public void CreateNewCustomer([FromBody] CustomerPoco newCustomer)
 {
     this.rentalBusinessLogic.CreateNewCustomer(newCustomer);
 }