예제 #1
0
        public async Task <ActionResult <customerDTO> > Createcustomer(customerDTO cus2)
        {
            var cus1 = cus2.toCustomer();

            _context.customers.Add(cus1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Getcustomer), new { id = cus1.id }, cus1));
        }
예제 #2
0
        public async Task <ActionResult <brandDTO> > CreateProduct(brandDTO b2)
        {
            var b1 = b2.toBrand();

            _context.brands.Add(b1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetBrand), new { id = b1.id }, b1));
        }
예제 #3
0
        public async Task <ActionResult <CategoryDTO> > Createcategory(CategoryDTO c2)
        {
            var c1 = c2.toCategory();

            _context.category.Add(c1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Getcategory), new { id = c1.id }, c1));
        }
예제 #4
0
        public async Task <ActionResult <CartDTO> > Createcart(CartDTO c)
        {
            var c1 = c.tocart();

            _context.cart.Add(c1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCart), new { id = c1.id }, c1));
        }
예제 #5
0
        public async Task <ActionResult <ProductDTO> > CreateProduct(ProductDTO p2)
        {
            var p1 = p2.toProduct();

            _context.product.Add(p1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetProduct), new { id = p1.id }, p1));
        }
예제 #6
0
        public async Task <ActionResult <SkuDTO> > CreateProduct(SkuDTO sku2)
        {
            var sku1 = sku2.tosku();

            _context.skus.Add(sku1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Getsku), new { id = sku1.id }, sku1));
        }
예제 #7
0
        public async Task <ActionResult <AddressDTO> > CreateProduct(AddressDTO ad2)
        {
            var ad1 = ad2.toAddress();

            _context.addresses.Add(ad1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Getaddress), new { id = ad1.id }, ad1));
        }
        public async Task <ActionResult <SelleraddressDTO> > Createaddress(SelleraddressDTO s)
        {
            var s1 = s.toselleraddress();

            _context.selleraddresses.Add(s1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Getaddress), new { id = s1.id }, s1));
        }
예제 #9
0
        public async Task <ActionResult <order_itemDTO> > CreateItem(order_itemDTO or2)
        {
            var or1 = or2.toorder_item();

            _context.orderitem.Add(or1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetOrderItem), new { id = or1.id }, or1));
        }
예제 #10
0
        public async Task <ActionResult <SellerDTO> > CreateSeller(SellerDTO s)
        {
            var s1 = s.toSeller();

            _context.seller.Add(s1);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetSeller), new { id = s1.id }, s1));
        }
예제 #11
0
        public async Task <ActionResult <OrderTableDTO> > CreateOrder([FromBody] OrderTableDTO orderDTO)
        {
            var orderEntity = orderDTO.toOrder();

            _context.ordertable.Add(orderEntity);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetOrder), new { id = orderEntity.id }, orderEntity));
        }
예제 #12
0
        public async Task <ActionResult <imageDTO> > CreateImage(imageDTO imgDTO)
        {
            var       imgEntity   = imgDTO.toimage();
            Base64Url base64Url   = new Base64Url(_environment);
            Image     physicalImg = base64Url.decode(imgEntity.url);

            imgEntity.url = base64Url.writeImage(physicalImg);
            _context.images.Add(imgEntity);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetImage), new { id = imgEntity.id }, imgEntity));
        }
예제 #13
0
        public async Task <IActionResult> login([FromBody] Login login)
        {
            var user = await userManager.FindByNameAsync(login.phone);

            if (user != null && await userManager.CheckPasswordAsync(user, login.password))
            {
                var userRole = await userManager.GetRolesAsync(user);

                var authclaims = new List <Claim>
                {
                    new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
                    new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                };
                foreach (var userrole in userRole)
                {
                    authclaims.Add(new Claim("role", userrole));
                }
                var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"]));
                var token          = new JwtSecurityToken(
                    issuer: _configuration["JWT:ValidIssuer"],
                    audience: _configuration["JWT:ValidAudience"],
                    expires: DateTime.Now.AddHours(500),
                    claims: authclaims,
                    signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
                    );
                var refreshObject = new Refreshtoken
                {
                    userName     = login.phone,
                    refreshToken = Guid.NewGuid().ToString()
                };
                await _ecommerContext.refreshtokens.AddAsync(refreshObject);

                await _ecommerContext.SaveChangesAsync();

                var token1    = new JwtSecurityTokenHandler().WriteToken(token);
                var expire    = token.ValidTo;
                var userrole1 = await userManager.IsInRoleAsync(user, "customer");


                return(Ok(new
                {
                    token = new JwtSecurityTokenHandler().WriteToken(token),
                    expiration = token.ValidTo,
                    refreshToken = refreshObject.refreshToken
                }));
            }
            return(Unauthorized(new Response {
                status = "Lỗi", message = "Tài khoản không hợp lệ"
            }));
        }