Ejemplo n.º 1
0
        public async Task <ActionResult> RegisterEmployer(EmployerCreateDto employerCreateDto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await EmployerFacade.Register(employerCreateDto);

                    var authTicket = new FormsAuthenticationTicket(1, employerCreateDto.Email, DateTime.Now,
                                                                   DateTime.Now.AddMinutes(30), false, "Employer");
                    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    HttpContext.Response.Cookies.Add(authCookie);

                    return(RedirectToAction("Index", "Home"));
                }
                catch (ArgumentException)
                {
                    ModelState.AddModelError("Username", "Account with that username already exists!");
                    return(View());
                }
            }

            return(View(employerCreateDto));
        }
Ejemplo n.º 2
0
        private static async Task TestRegister(Mapper mapper)
        {
            EmployerFacade employerFacade = new EmployerFacade(Provider,
                                                               new EmployerService(mapper, new EmployerRepository(Provider),
                                                                                   new EmployerQueryObject(mapper, new EntityFrameworkQuery <Employer>(Provider))));
            await employerFacade.Register(new EmployerCreateDto
            {
                Name        = "Employer1",
                Password    = "******",
                Address     = "Brno",
                Email       = "*****@*****.**",
                PhoneNumber = "+421902333666"
            }
                                          );

            var results = await employerFacade.GetAllEmployersAsync();

            foreach (var resultsItem in results.Items)
            {
                Console.WriteLine(resultsItem.Name, resultsItem.Id);
            }
        }