Esempio n. 1
0
        public async Task <IActionResult> PutGame([FromRoute] int id, [FromBody] Game game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != game.Id)
            {
                return(BadRequest());
            }

            _context.Entry(game).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,Address,City,PIN,DateOfBirth,Email,IsEmployee,IsVolunteer,IsOutsorced")] Person person)
        {
            if (id != person.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Gender,Console")] Game game)
        {
            if (id != game.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(game);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GameExists(game.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(game));
        }
Esempio n. 4
0
        public async Task <User> SeedAsync()
        {
            try
            {
                var roles = GetDefaultRoles();
                var user  = await GetAdminUserAsync(_passwordHasher, _context);

                if (!_context.Roles.Any())
                {
                    _context.Roles.AddRange(roles);
                }

                if (!_context.Users.Any())
                {
                    _context.Users.Add(user);
                }

                await _context.SaveChangesAsync();

                if (!_context.UserRoles.Any())
                {
                    var adminRoles = GetAdminRoles(
                        await _context.Users.Where(x => x.UserName == "*****@*****.**").SingleOrDefaultAsync(),
                        await _context.Roles.ToListAsync());
                    _context.UserRoles.AddRange(adminRoles);
                    await _context.SaveChangesAsync();
                }

                var dto = Mapper.Map <DtoUser>(user);

                var @event = new ApplicantsChanged
                {
                    Created = new[] { dto }
                };

                _eventBus.Publish(@event);

                return(user);
            }
            catch (SqlException ex)
            {
                _logger.LogError("Error when try to add admin user: {@ex}", ex);
                throw;
            }
        }
Esempio n. 5
0
        public async Task <User> RegisterAsync(RegistrationViewModel model, string role)
        {
            await _context.SaveChangesAsync();

            var user = new User
            {
                Id                 = Guid.NewGuid().ToString("D"),
                FirstName          = model.FirstName,
                LastName           = model.LastName,
                BirthDate          = model.BirthDate,
                GenderId           = model.GenderId,
                AreaId             = model.AreaId,
                Email              = model.Email,
                UserName           = model.Email,
                SecurityStamp      = Guid.NewGuid().ToString("D"),
                NormalizedEmail    = model.Email.ToUpper(),
                NormalizedUserName = model.Email.ToUpper()
            };

            var result = await _userManager.CreateAsync(user, model.Password);

            var roleResult = await _userManager.AddToRoleAsync(user, role);

            if (roleResult.Errors.Any())
            {
                OnErrorsOccured?.Invoke(roleResult);
            }

            if (role == IdentityConfig.DefaultRoles.EDUCATIONAL_INSTITUTION_MANAGER)
            {
                await AddEducationalInstitutionManagerProperties(model, user.Id);
            }

            if (role == IdentityConfig.DefaultRoles.EMPLOYER_MANAGER)
            {
                await AddEmployerManagerProperties(model, user.Id);
            }

            return(user);
        }