public async Task <IActionResult> PutAccess([FromRoute] int id, [FromBody] Access access)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != access.AccessId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostAccess([FromBody] Access access)
        {
            try
            {
                await _accessContext.Accesses.AddAsync(access);

                await _accessContext.SaveChangesAsync();

                return(Json(new { status = true, data = access }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { status = false, message = e.Message }));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <User> > Post([FromBody] CreateUser createUser, [FromServices] AccessContext context)
        {
            User user = new User
            {
                Name      = createUser.Name,
                LastName  = createUser.LastName,
                BirthDate = createUser.BirthDate
            };

            var response = await context.User.AddAsync(user);


            var identityUser = new IdentityUser
            {
                Id             = user.Id,
                UserName       = createUser.Email.Trim(),
                Email          = createUser.Email.Trim(),
                EmailConfirmed = true,
            };


            var result = await _userManager.CreateAsync(identityUser, createUser.Password);

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

            await context.SaveChangesAsync();


            string token = await GetToken(createUser.Email);

            var jwt = new TokenResponse(token);


            return(Ok(jwt));
        }
        public static async Task<bool> UpdateUserAccountLevel(this Booking booking, AccessContext Context, bool ignoreStatus = false)
        {
            if ( (booking.Status == BookingStatus.Reservada|| booking.Status == BookingStatus.Pendiente) || ignoreStatus)
            {
                var center = await Context.Centers.Where(c => c.Fields.Any(f => f.Id == booking.Idcancha))
                                                .FirstOrDefaultAsync();

                if (!await Context.AccountAccess.AnyAsync(c => c.UserId == booking.Userid.ToString()))
                {
                    Context.AccountAccess.Add(new AccountAccessLevel()
                    {
                        UserId = booking.Userid.ToString(),
                        Center = center,
                    });
                    await Context.SaveChangesAsync();
                }
                return true;
            }
            return false;
        }