예제 #1
0
        public async Task <IActionResult> PostAddress([FromBody] Address address)
        {
            var addressList = await _context.Addresses.ToListAsync();

            string access_token = await HttpContext.GetTokenAsync("access_token");

            var user = _token.GetPayloadAsync(access_token);

            address.UserId = user.UserId;
            addressList    = addressList.Where(a => a.UserId == address.UserId).ToList();



            if (addressList.Count() > 0)
            {
                address.IsDefault = false;
            }
            else
            {
                address.IsDefault = true;
            }

            await _context.AddAsync(address);

            await _context.SaveChangesAsync();

            return(Ok(new { success = true, data = address }));
        }