Ejemplo n.º 1
0
 public static ClaimsIdentity ValidateRegistry(CustomerDTO c,ICustomerDTOService _customerDtoService,out string error)
 {
     error = string.Empty;
     var alreadyAdded = Task.Run(() => _customerDtoService.Get(c.userName)).Result;
     if (alreadyAdded != null)
     {
         error = Messages.UserExists;
         return null;
     }
     var isOk = Task.Run((() => _customerDtoService.Post(c))).Result;
     if (isOk)
     {
         var user = Task.Run((() => _customerDtoService.Get((c.userName)))).Result;
         IList<Claim> claimCollection = new List<Claim>
         {
             new Claim(ClaimTypes.Name, user.userName),
             new Claim(ClaimTypes.Role,Roles.UserRole)
         };
         var claimsIdentity = new ClaimsIdentity(claimCollection, DefaultAuthenticationTypes.ApplicationCookie);
         return claimsIdentity;
     }
     else
     {
         error = Messages.UnexpecedDBError;
         return null;
     }
 }
Ejemplo n.º 2
0
 public CarsOrderViewModel(StationDTO station,CustomerDTO w)
 {
     this.station = station;
     this.w = w;
     SearchCars();
     CarAmount = 0;
 }
Ejemplo n.º 3
0
        public void RegistryHelperAlreadyInDbTest()
        {
            CustomerDTO c=new CustomerDTO() {userName = "******"};
            var mockService=new Mock<ICustomerDTOService>();

            mockService.Setup(s => s.Get(c.userName)).Returns(Task.FromResult(c));
            string msg;
            var result = AccountHelper.ValidateRegistry(c, mockService.Object, out msg);

            Assert.IsTrue(result==null);
            Assert.IsTrue(msg== Messages.UserExists);
        }
Ejemplo n.º 4
0
 public void Update(CustomerDTO item)
 {
     var customer = entities.Customers.FirstOrDefault(s => s.Id == item.Id);
     if(customer!=null)
     {
         customer.firstName = item.firstName;
         customer.creditCardNumber = item.creditCardNumber;
         customer.lastName = item.lastName;
         customer.pesel = item.pesel;
         customer.phoneNumber = item.phoneNumber;
         customer.password = item.password;
         entities.SaveChanges();
     }
 }
Ejemplo n.º 5
0
        public void LoginHelperCustomerSuccessfullLoginTest()
        {
            var mockCustomerService = new Mock<ICustomerDTOService>();
            var mockWorkerService = new Mock<IWorkerDTOService>();
            string login = "******";
            string password = "******";
            CustomerDTO c=new CustomerDTO() {userName = login,password = SecurePasswordHasher.Hash(password)};

            mockCustomerService.Setup(s => s.Get("test")).Returns(Task.FromResult(c));
            mockWorkerService.Setup(s => s.Get(login)).Returns(Task.FromResult((WorkerDTO) null));

            string msg;
            var result=AccountHelper.ValidateLogin(login, password, mockCustomerService.Object, mockWorkerService.Object, out msg);

            Assert.IsTrue(result!=null);
            Assert.IsTrue(msg==string.Empty);
        }
Ejemplo n.º 6
0
        public void RegistryHelperAddToDBTest()
        {
            CustomerDTO c = new CustomerDTO() { userName = "******" };
            var mockService = new Mock<ICustomerDTOService>();

            mockService.SetupSequence(x => x.Get(c.userName))
            .Returns(Task.FromResult((CustomerDTO)null))
            .Returns(Task.FromResult(c));

            mockService.Setup(x => x.Post(c)).Returns(Task.FromResult(true));

            string msg;
            var result = AccountHelper.ValidateRegistry(c, mockService.Object, out msg);

            Assert.IsTrue(result != null);
            Assert.IsTrue(msg == string.Empty);
        }
Ejemplo n.º 7
0
        public ActionResult UserProfile(EditProfileViewModel model, string returnUrl)
        {
            string msg;
            CustomerDTO cust = new CustomerDTO();
            try
            {
                if (ModelState.IsValid)
                {
                    cust = Task.Run(() => _customerService.Get(User.Identity.Name)).Result;
                    model.password = cust.password;
                    CustomerDTO customer = Mapper.Map<CustomerDTO>(model);
                    customer.Id = cust.Id;
                    
                    var custPut = Task.Run((() => _customerService.Put(customer))).Result;
                    if (custPut)
                        msg = "Saved Successfully";
                    else
                    {
                        msg = "Something went wrong";
                        ModelState.AddModelError("", msg);
                        RedirectToRoute(returnUrl);
                    }
                }
                else
                {
                    msg = "Validation profie not successfull";
                    ModelState.AddModelError("", msg);
                    RedirectToRoute(returnUrl);
                }
            }
            catch (Exception ex)
            {
                msg = "Error occured:" + ex.Message;
                ModelState.AddModelError("", msg);
                RedirectToRoute(returnUrl);
            }

            model.IsEdited = true;

            //model = Mapper.Map<EditProfileViewModel>(cust);
            return View(model);
        }
Ejemplo n.º 8
0
 private async void Accept()
 {
     //using (var entities = new MobilekEntities())
     {
         var service = new Mobilek.Services.CustomerDTOService(TheCustomer.userName,TheCustomer.password);
         CustomerDTO c = new CustomerDTO();
         c.firstName = FirstName;
         c.lastName = LastName;
         c.phoneNumber = PhoneNr;
         c.pesel = Pesel;
         c.email = Email;
         c.creditCardNumber = CreditCardNr;
         c.Id = theCustomer.Id;
         service.Put(c);
         TheCustomer = c;
     }
     var msg = new FireRefresh();
     Messenger.Default.Send<FireRefresh>(msg);
     SendIsModifiedCollectionInfo();
     Exit();
 }
Ejemplo n.º 9
0
 public ProfileEditViewModel(CustomerDTO customer)
 {
     TheCustomer = customer;
     FirstName = customer.firstName;
     LastName = customer.lastName;
     Email = customer.email;
     PhoneNr = customer.phoneNumber;
     CreditCardNr = customer.creditCardNumber;
     Pesel = customer.pesel;
 }
Ejemplo n.º 10
0
 public StationOrderViewModel(string stationType, CustomerDTO customer)
 {
     w = customer;
     GetStations();
     this.stationType = stationType;
     this.customer = customer;
 }
Ejemplo n.º 11
0
 public ProfileEditView(CustomerDTO customer)
 {
     InitializeComponent();
     DataContext = new ProfileEditViewModel(customer);
 }
Ejemplo n.º 12
0
 public StationOrderView(string stationType, CustomerDTO customer)
 {
     InitializeComponent();
     DataContext = new StationOrderViewModel(stationType, customer);
 }
Ejemplo n.º 13
0
        private async void ToCustomer(object parameter)
        {
            var passwordBox = parameter as PasswordBox;
            var password = passwordBox.Password;
            Password = password;
            ValidateRegistry();
            if (validationErrors.Count == 0)
            {
                //using (MobilekEntities entities = new MobilekEntities())
                {
                    var hash = SecurePasswordHasher.Hash(password);
                    CustomerDTO customer = new CustomerDTO()
                    {
                        firstName = FirstName,
                        lastName = Surname,
                        creditCardNumber = CreditCardNr,
                        pesel = Pesel,
                        phoneNumber = PhoneNr,
                        userName = UserName,
                        password = hash,
                        email = Email
                    };
                    //entities.Customers.Add(customer);
                    //entities.SaveChanges();
                    var service = new Mobilek.Services.CustomerDTOService("", "");
                    await service.Post(customer);
                }
                RegistrationSuccessful = "User name: " + UserName + " was successfully added";
                FirstName = ""; Surname = ""; Email = ""; PhoneNr = ""; Pesel = ""; CreditCardNr = "";
                Password = ""; RepeatPassword = ""; UserName = ""; Login_Password = ""; Login_UserName = "";
                var msg = new ChangePageHelper() { PageName = new UserLoginViewModel() };
                Messenger.Default.Send<ChangePageHelper>(msg);
            }

        }
Ejemplo n.º 14
0
 public void Add(CustomerDTO item)
 {
     var c = Mapper.Map<Customer>(item);
     entities.Customers.Add(c);
     entities.SaveChanges();
 }
Ejemplo n.º 15
0
        public void ChangePasswordUserInCorrectPasswordTest()
        {
            var mockCustomerService = new Mock<ICustomerDTOService>();
            var mockWorkerService = new Mock<IWorkerDTOService>();
            string login = "******";
            string password = "******";
            CustomerDTO customer = new CustomerDTO() { userName = login, password = SecurePasswordHasher.Hash(password+password) };


            mockCustomerService.Setup(s => s.Get(login)).Returns(Task.FromResult(customer));
            mockCustomerService.Setup(s => s.Put(customer)).Returns(Task.FromResult(true));

            Claim c = new Claim(ClaimTypes.Role, Roles.UserRole);
            string msg;
            var result = AccountHelper.ValidateChangePassword(c, login, password, password + password,
                mockCustomerService.Object, mockWorkerService.Object, out msg);

            Assert.IsTrue(!result);
            Assert.IsTrue(msg != string.Empty);
            Assert.IsTrue(msg==Messages.IncorrectPassword);
        }
Ejemplo n.º 16
0
 public UserPanelViewModel(CustomerDTO customer)
 {
     TheCustomer = customer;
     GetOrders();
     ReceiveCollectionInfo();
     StartTime = DateTime.Today;
     EndTime = DateTime.Today;
 }
Ejemplo n.º 17
0
        private async void ToAccount(object parameter)
        {
            var passwordBox = parameter as PasswordBox;
            var password = passwordBox.Password;
            Login_Password = password;
            ValidateLogin();
            if (validationErrors.Count == 0)
            {
                CustomerDTO customer = new CustomerDTO();
                var service = new Mobilek.Services.CustomerDTOService(Login_UserName, Login_Password);
                var users = await service.Get();
                customer = users.FirstOrDefault(x => x.userName == Login_UserName);

                var msg = new ChangePageHelper() { PageName = new UserPanelViewModel(customer) };
                Messenger.Default.Send<ChangePageHelper>(msg);

            }
            //var msg2 = new ChangePanelHelper() { panelType = PanelType.User };
            //Messenger.Default.Send<ChangePanelHelper>(msg2); 
        }
Ejemplo n.º 18
0
 public async Task<bool> Post(CustomerDTO item)
 {
     return await this.Post<CustomerDTO, bool>("POST", item);
 }
Ejemplo n.º 19
0
 public CarsOrderView(StationDTO s,CustomerDTO w)
 {
     InitializeComponent();
     DataContext = new CarsOrderViewModel(s,w);
 }
Ejemplo n.º 20
0
 public async Task<bool> Put(CustomerDTO item)
 {
     return await this.Put<CustomerDTO, bool>("PUT", item);
 }