Esempio n. 1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            if (id == null)
            {
                return(NotFound());
            }

            var employee = await _context.Employees
                           .FirstOrDefaultAsync(m => m.Id == id);

            if (employee == null)
            {
                return(NotFound());
            }

            Input = employee;

            GendersList          = new SelectList((await _context.Genders.ToListAsync()).Select(gender => gender.Name));
            StatesList           = new SelectList((await _context.States.ToListAsync()).Select(state => state.Name));
            ProgrammingLanguages = await _context.ProgrammingLanguages.ToListAsync();

            return(Page());
        }
Esempio n. 2
0
        public async Task <IActionResult> OnGetAsync()
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            HttpContext.Response.Cookies.Delete("AuthCookies");

            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            return(Page());
        }
Esempio n. 3
0
        public async Task <IActionResult> OnGetAsync()
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            GendersList          = new SelectList((await _context.Genders.ToListAsync()).Select(gender => gender.Name));
            StatesList           = new SelectList((await _context.States.ToListAsync()).Select(state => state.Name));
            ProgrammingLanguages = await _context.ProgrammingLanguages.ToListAsync();

            return(Page());
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync(InputModel input, string[] inputs)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var gender = await _context.Genders.Where(gender => gender.Name == input.Gender).FirstOrDefaultAsync();

            var state = await _context.States.Where(state => state.Name == input.State).FirstOrDefaultAsync();

            var newEmployee = new Employee()
            {
                Age     = input.Age,
                Name    = input.Name,
                Gender  = gender,
                State   = state,
                Surname = input.Surname
            };

            if (inputs != null && inputs.Length > 0)
            {
                var languages = await _context.ProgrammingLanguages.Where(lang => inputs.Contains(lang.Name)).ToListAsync();

                var employeeExperience = new List <EmployeeExperience>();

                foreach (var lang in languages)
                {
                    employeeExperience.Add(new EmployeeExperience()
                    {
                        ProgrammingLanguage = lang,
                        Employee            = newEmployee
                    });
                }

                await _context.AddAsync <Employee>(newEmployee);

                await _context.AddRangeAsync(employeeExperience);

                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            await _context.AddRangeAsync(newEmployee);

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 5
0
        public async Task OnGetAsync(string returnUrl = null)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            if (!string.IsNullOrEmpty(ErrorMessage))
            {
                ModelState.AddModelError(string.Empty, ErrorMessage);
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            ReturnUrl = returnUrl;
        }
Esempio n. 6
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            if (id == null)
            {
                return(NotFound());
            }

            Employee = await _context.Employees.FirstOrDefaultAsync(m => m.Id == id);

            if (Employee == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 7
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                var account = await _context.Accounts.Where(prop => prop.Login == Input.Login).FirstOrDefaultAsync();

                if (account == null)
                {
                    ModelState.AddModelError(string.Empty, "Такого пользователя не существует.");
                    return(Page());
                }

                var result = new PasswordHasher <EmployeesApplication.Models.Account>().VerifyHashedPassword(
                    user: account,
                    hashedPassword: account.PasswordHash,
                    providedPassword: Input.Password);

                if (result != PasswordVerificationResult.Success)
                {
                    ModelState.AddModelError(string.Empty, "Не правильный пароль");
                    return(Page());
                }

                var claims = new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, account.Login),
                    new Claim(ClaimTypes.Role, "User")
                };

                var identity = new ClaimsIdentity(
                    claims,
                    CookieAuthenticationDefaults.AuthenticationScheme);

                await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    new ClaimsPrincipal(identity));

                return(RedirectToPage("/Home/Index"));
            }

            return(Page());
        }
Esempio n. 8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            if (id == null)
            {
                return(NotFound());
            }

            Employee = await _context.Employees.FindAsync(id);

            if (Employee != null)
            {
                _context.Employees.Remove(Employee);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 9
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            if (id == null)
            {
                return(NotFound());
            }

            Employee = await _context.Employees
                       .Include(prop => prop.Gender)
                       .Include(prop => prop.State)
                       .FirstOrDefaultAsync(m => m.Id == id);

            Experience = await _context.UsersExperience
                         .Include(prop => prop.ProgrammingLanguage)
                         .Where(prop => prop.Employee == Employee).ToListAsync();

            if (Employee == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 10
0
        public async Task OnGetAsync()
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            Employees = await _context.Employees.ToListAsync();
        }
Esempio n. 11
0
        public async Task <IActionResult> OnPostAsync(InputModel input, string[] inputs)
        {
            await TimeStamper.TimeStampAsync(_context, HttpContext);

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var editingEmployee = await _context.Employees
                                  .Include(prop => prop.Gender)
                                  .Include(prop => prop.State)
                                  .Include(prop => prop.EmployeesExperience)
                                  .ThenInclude(prop => prop.ProgrammingLanguage)
                                  .Where(empl => empl.Id == input.Id).FirstOrDefaultAsync();

            var currentProgrammingLngs = editingEmployee.EmployeesExperience.Select(prop => prop.ProgrammingLanguage).ToList();

            if (ExperienceIsChanged(currentProgrammingLngs.Select(pl => pl.Name).ToList(), inputs))
            {
                var currEmployeeExp = editingEmployee.EmployeesExperience;
                _context.UsersExperience.RemoveRange(currEmployeeExp);
                await _context.SaveChangesAsync();

                var newEmployeeExperience = new List <EmployeeExperience>();

                var languages = await _context.ProgrammingLanguages.ToListAsync();

                languages = languages.Where(lang => inputs.Contains(lang.Name)).ToList();

                foreach (var lang in languages)
                {
                    newEmployeeExperience.Add(new EmployeeExperience()
                    {
                        Employee            = editingEmployee,
                        ProgrammingLanguage = lang
                    });
                }

                _context.UsersExperience.UpdateRange(newEmployeeExperience);
                await _context.SaveChangesAsync();
            }

            if (editingEmployee.Gender.Name != input.Gender)
            {
                var updatedGender = await _context.Genders.Where(gender => gender.Name == input.Gender).FirstOrDefaultAsync();

                editingEmployee.Gender = updatedGender;
            }
            if (editingEmployee.State.Name != input.State)
            {
                var updatedState = await _context.States.Where(state => state.Name == input.State).FirstOrDefaultAsync();

                editingEmployee.State = updatedState;
            }

            editingEmployee.Age     = input.Age;
            editingEmployee.Name    = input.Name;
            editingEmployee.Surname = input.Surname;

            _context.Employees.Update(editingEmployee);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(RedirectToPage("./Index"));
            }

            return(RedirectToPage("./Index"));
        }