public async Task <IActionResult> PutDonHang(int id, DonHang donHang)
        {
            if (id != donHang.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> PutTinh(int id, Tinh tinh)
        {
            if (id != tinh.Ma)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #3
0
        public async Task <ActionResult <Xe> > PostImages(int id)
        {
            var xe = _context.Xe.Find(id);

            if (xe == null)
            {
                return(NotFound());
            }
            xe.Moban = !xe.Moban;
            _context.Entry(xe).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch
            {
                return(NotFound());
            }
            return(Ok(xe));
        }
Example #4
0
        public async Task <IActionResult> update([FromBody] Tinh tinh)
        {
            try
            {
                _context.Entry(tinh).State = EntityState.Modified;

                await _context.SaveChangesAsync();

                return(Ok(tinh));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TinhExists(tinh.Ma))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Example #5
0
        public async Task <IActionResult> PutImages(int id, [FromForm(Name = "file")] IFormFile file, string loai)
        {
            if (file == null)
            {
                return(NotFound());
            }
            var      ima = _context.Images.Find(id);
            string   src;
            var      image         = new Images();
            DateTime s             = DateTime.Now;
            string   date          = s.ToString();
            var      charsToRemove = new string[] { "@", ",", ".", ";", "'", "-", ":", " " };

            foreach (var c in charsToRemove)
            {
                date = date.Replace(c, string.Empty);
            }
            if (file != null)
            {
                string path_Root = _env.WebRootPath;
                if (path_Root == null)
                {
                    return(NotFound());
                }

                string path_to_Images = path_Root + "\\Images\\" + date + file.FileName;

                //< Copy File to Target >
                src = "\\Images\\" + date + file.FileName;

                using (var stream = new FileStream(path_to_Images, FileMode.Create))

                {
                    await file.CopyToAsync(stream);
                }

                if (id == 0)
                {
                    string idcar          = file.FileName;
                    var    charsToRemove2 = new string[] { " ", ".", "p", "n", "g" };
                    foreach (var c in charsToRemove2)
                    {
                        idcar = idcar.Replace(c, string.Empty);
                    }
                    var xe = _context.Xe.Find(Convert.ToInt32(idcar));
                    if (xe == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        xe.Hinh = src;
                        _context.Entry(xe).State = EntityState.Modified;

                        try
                        {
                            await _context.SaveChangesAsync();

                            return(Ok(xe));
                        }
                        catch {
                        }
                    }
                }
                else
                {
                    image.XeId = ima.XeId;
                    ima.Src    = src;
                    _context.Entry(ima).State = EntityState.Modified;
                    try
                    {
                        await _context.SaveChangesAsync();
                    }
                    catch
                    {
                    }
                }
                //</ Copy File to Target >
            }
            return(Ok(image));
        }
Example #6
0
        public async Task <IActionResult> PutXe(Xe xe)
        {
            var x   = _context.Xe.Find(xe.Id);
            Xe  ren = new Xe();

            if (xe.MaHuyen != null)
            {
                x.MaHuyen = xe.MaHuyen;
                var huyen = _context.Huyen.Include(a => a.MaTinhNavigation).Where(a => a.Id == xe.MaHuyen).SingleOrDefault();

                if (huyen == null)
                {
                    return(NotFound());
                }
                x.Huyen = huyen.TenHuyen;
                x.Tinh  = huyen.MaTinhNavigation.TenTinh;
            }

            else
            if (xe.MaHangXe != null)
            {
                var Hangxe = _context.HangXe.Find(xe.MaHangXe);
                if (Hangxe == null)
                {
                    return(NotFound());
                }

                if (!string.IsNullOrEmpty(xe.Tenxe))
                {
                    x.Tenxe = xe.Tenxe;
                }

                x.MaHangXe = xe.MaHangXe;
                x.TenHang  = Hangxe.TenHang;
            }
            else
            {
                x.BienSo = xe.BienSo;
                x.SoKM   = xe.SoKM;
                x.Gia    = xe.Gia;
            }



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

            try
            {
                await _context.SaveChangesAsync();

                ren = _context.Xe.Find(xe.Id);
                ren.MaHuyenNavigation  = null;
                ren.MaHangXeNavigation = null;
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!XeExists(xe.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(ren));
        }