예제 #1
0
        public async Task <IActionResult> Update(Tbl_productRequest request)
        {
            if (request.ImageFile == null)
            {
                request.ImageFile = null;
                await _nhanSuApiClient.Update(request);
            }
            else
            {
                string wwwRootPath = _hostEnvironment.WebRootPath;
                string fileName    = Path.GetFileNameWithoutExtension(request.ImageFile.FileName);
                string extension   = Path.GetExtension(request.ImageFile.FileName);
                request.image = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                string path = Path.Combine(wwwRootPath + "/image/", fileName);
                request.image = fileName;

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await request.ImageFile.CopyToAsync(fileStream);

                    request.ImageFile = null;
                    await _nhanSuApiClient.Update(request);
                }
            }


            return(RedirectToAction("index"));
        }
예제 #2
0
 public IActionResult Login(Tbl_productRequest request)
 {
     if (request.username == "giamdoc" && request.password == "giamdoc")
     {
         return(Redirect("/"));
     }
     return(Redirect("/Home/Login"));
 }
예제 #3
0
 public IActionResult Login(Tbl_productRequest request)
 {
     if (request.username == "Nishat" && request.password == "1234")
     {
         return(Redirect("https://localhost:44345/"));
         // return RedirectToAction("index");
     }
     return(Redirect("/Home/Login"));
     // return RedirectToAction("index");
 }
예제 #4
0
        public async Task <int> Delete(Tbl_productRequest tbl_productRequest)
        {
            var tbl_product = new tbl_product()
            {
                id = tbl_productRequest.id
            };

            _context.tbl_products.Remove(tbl_product);

            return(await _context.SaveChangesAsync());
        }
예제 #5
0
        public async Task <string> Update(Tbl_productRequest request)
        {
            var json        = JsonConvert.SerializeObject(request);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");

            var client = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri("https://localhost:44358");
            var response = await client.PostAsync("api/Tbl_product/Update", httpContent);

            return(await response.Content.ReadAsStringAsync());
        }
예제 #6
0
        public async Task <int> Create(Tbl_productRequest tbl_productRequest)
        {
            var tbl_product = new tbl_product()
            {
                name     = tbl_productRequest.name,
                price    = tbl_productRequest.price,
                image    = tbl_productRequest.image,
                category = tbl_productRequest.category
            };

            _context.tbl_products.Add(tbl_product);

            return(await _context.SaveChangesAsync());
        }
예제 #7
0
        public async Task <List <Tbl_productResponse> > SearchProduct(Tbl_productRequest tbl_productRequest)
        {
            var query = from pr in _context.tbl_products
                        where EF.Functions.Like(pr.name, tbl_productRequest.name)
                        select new { pr };

            return(await query.Select(x => new Tbl_productResponse()
            {
                id = x.pr.id,
                name = x.pr.name,
                price = x.pr.price,
                image = x.pr.image,
                category = x.pr.category
            }).ToListAsync());
        }
 public async Task <IActionResult> SearchProduct([FromBody] Tbl_productRequest request)
 {
     return(Ok(await _nhanSuSerive.SearchProduct(request)));
 }
 public async Task <IActionResult> Delete([FromBody] Tbl_productRequest request)
 {
     return(Ok(await _nhanSuSerive.Delete(request)));
 }