Exemplo n.º 1
0
        public ActionResult SuaNSX(String id, HttpPostedFileBase logoHSX)
        {
            ViewBag.MaHang = new SelectList(db.HangSXes.ToList().OrderBy(n => n.TenHang), "MaHang", "TenHang");
            HangSX hang = db.HangSXes.SingleOrDefault(n => n.MaHang == id);

            if (logoHSX == null)
            {
                ViewBag.Thongbao = "Vui lòng chọn ảnh mới";
                UpdateModel(hang);
                db.SubmitChanges();
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var fileName = Path.GetFileName(logoHSX.FileName);
                    var path     = Path.Combine(Server.MapPath("~/images"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        ViewBag.Thongbao = "Hình ảnh đã tồn tại";
                    }
                    else
                    {
                        logoHSX.SaveAs(path);
                    }
                    hang.Logo = fileName;
                    UpdateModel(hang);
                    db.SubmitChanges();
                }
            }
            return(RedirectToAction("NhaSanXuat", "Admin"));
        }
Exemplo n.º 2
0
        public IHttpActionResult PostHangSX(HangSX hangSX)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.hangSXs.Add(hangSX);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (HangSXExists(hangSX.IDHSX))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = hangSX.IDHSX }, hangSX));
        }
Exemplo n.º 3
0
        public IHttpActionResult PutHangSX(string id, HangSX hangSX)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != hangSX.IDHSX)
            {
                return(BadRequest());
            }

            db.Entry(hangSX).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HangSXExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
 // GET: Administrator/HangSXes/Delete/5
 public ActionResult Delete(int[] idHang)
 {
     foreach (var i in idHang)
     {
         HangSX hsx = db.HangSXes.Find(i);
         db.HangSXes.Remove(hsx);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "IdHang,Mota,Website,LienHe,UTien,ThucThi,NgonNgu")] HangSX hangSX)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hangSX).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hangSX));
 }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "IdHang,Mota,Website,LienHe,UTien,ThucThi,NgonNgu")] HangSX hangSX)
        {
            if (ModelState.IsValid)
            {
                db.HangSXes.Add(hangSX);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hangSX));
        }
Exemplo n.º 7
0
        public IHttpActionResult GetHangSX(string id)
        {
            HangSX hangSX = db.hangSXs.Find(id);

            if (hangSX == null)
            {
                return(NotFound());
            }

            return(Ok(hangSX));
        }
Exemplo n.º 8
0
        public ActionResult SuaNSX(string id)
        {
            HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id);

            if (hsx == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(hsx));
        }
Exemplo n.º 9
0
        public ActionResult ChiTietNSX(string id)
        {
            HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id);

            //ViewBag.MaDienThoai = dt.MaDienThoai;
            if (hsx == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(hsx));
        }
Exemplo n.º 10
0
        public IHttpActionResult PostHangSX(HangSX hangSX)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.HangSXes.Add(hangSX);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = hangSX.IdHang }, hangSX));
        }
Exemplo n.º 11
0
        // GET: Administrator/HangSXes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HangSX hangSX = db.HangSXes.Find(id);

            if (hangSX == null)
            {
                return(HttpNotFound());
            }
            return(View(hangSX));
        }
Exemplo n.º 12
0
        public IHttpActionResult DeleteHangSX(string id)
        {
            HangSX hangSX = db.hangSXs.Find(id);

            if (hangSX == null)
            {
                return(NotFound());
            }

            db.hangSXs.Remove(hangSX);
            db.SaveChanges();

            return(Ok(hangSX));
        }
Exemplo n.º 13
0
        public HangSX getElement(string id)
        {
            string    query     = "select * from HANGSX where MAHSX = '" + id + "'";
            DataTable dataTable = DocCSDL(query);
            HangSX    hangSX1   = null;

            if (dataTable != null || dataTable.Rows.Count != 0)
            {
                int    ma      = Convert.ToInt32(dataTable.Rows[0][0]);
                string ten     = dataTable.Rows[0][1].ToString();
                string quocGia = dataTable.Rows[0][2].ToString();
                hangSX1 = new HangSX(ma, ten, quocGia);
            }
            return(hangSX1);
        }
Exemplo n.º 14
0
 public ActionResult Create(HangSX a)
 {
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://localhost:54779/api/");
         var postTask = client.PostAsJsonAsync("HangSXAdmin", a);
         postTask.Wait();
         var kq = postTask.Result;
         if (kq.IsSuccessStatusCode)
         {
             return(RedirectToAction("Index"));
         }
     }
     ModelState.AddModelError(string.Empty, "Error");
     return(View(a));
 }
Exemplo n.º 15
0
        public ActionResult Edit(HangSX a)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:54779/api/");
                var putTask = client.PutAsJsonAsync("HangSXAdmin/" + a.IdHang, a);
                putTask.Wait();

                var kq = putTask.Result;

                if (kq.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
                return(View(a));
            }
        }
Exemplo n.º 16
0
        public IHttpActionResult PutHangSX(int id, HangSX hangSX)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != hangSX.IdHang)
            {
                return(BadRequest());
            }

            db.Entry(hangSX).State = EntityState.Modified;

            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 17
0
        public ViewResult sanPhamTheoHang(string MaHSX = "SSU")
        {
            HangSX hangSX = db.HangSXes.SingleOrDefault(n => n.MaHSX == MaHSX);

            if (hangSX == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            List <SanPham> lstSanPham = db.SanPhams.Where(n => n.MaHSX == MaHSX).OrderBy(n => n.MaHSX).ToList();

            if (lstSanPham.Count == 0)
            {
                ViewBag.SanPham = "Không có sản phẩm nào!";
            }
            ViewBag.lstSanPham = db.SanPhams.ToList();
            return(View(lstSanPham));
        }
Exemplo n.º 18
0
        // GET: Admin/NguoiDungs/Edit/5
        public ActionResult Edit(int id)
        {
            HangSX hangSX = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:54779/api/");
                var edit = client.GetAsync("HangSXAdmin/?id=" + id.ToString());
                edit.Wait();
                var kq = edit.Result;
                if (kq.IsSuccessStatusCode)
                {
                    var readTask = kq.Content.ReadAsAsync <HangSX>();
                    readTask.Wait();
                    hangSX = readTask.Result;
                }
            }
            return(View(hangSX));
        }
Exemplo n.º 19
0
        public ActionResult XacNhanXoaNSX(string id)
        {
            try {
                HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id);
                var    kt  = db.Giays.Where(x => x.MaHang == id).ToList();
                //if (hsx == null)
                //{
                //    response.statuscode = 404;
                //    return null;
                //}
                if (kt != null)
                {
                    ViewData["Error"] = "Vui lòng xóa sản phẩm thuộc hãng giày này trước";
                    db.SubmitChanges();
                    return(RedirectToAction("NhaSanXuat"));
                }

                db.HangSXes.DeleteOnSubmit(hsx);
            }
            catch (Exception ex)
            {
                ViewBag.onError = "Vui lòng xóa sản phẩm thuộc hãng giày này trước";
                //db.SubmitChanges();
                return(RedirectToAction("NhaSanXuat"));
            }
            //HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id);

            //if (hsx == null)
            //{
            //    Response.StatusCode = 404;
            //    return null;
            //}

            //db.HangSXes.DeleteOnSubmit(hsx);
            //db.SubmitChanges();

            return(RedirectToAction("NhaSanXuat"));
        }
Exemplo n.º 20
0
        public ActionResult ThemNSX(HangSX hsx, HttpPostedFileBase logoNSX, FormCollection fc)
        {
            var MaHang = fc["MaHang"];
            var khoa   = db.HangSXes.Where(x => x.MaHang.Equals(MaHang)).ToList();

            if (khoa.Count == 0)
            {
                if (logoNSX == null)
                {
                    ViewBag.Thongbao = "Vui lòng chọn hình ảnh";
                    return(View());
                }
                else
                {
                    var filename = Path.GetFileName(logoNSX.FileName);
                    var path     = Path.Combine(Server.MapPath("~/images"), filename);

                    if (System.IO.File.Exists(path))
                    {
                        ViewBag.Thongbao = "Hình ảnh đã tồn tại";
                    }
                    else
                    {
                        logoNSX.SaveAs(path);
                    }
                    hsx.MaHang = MaHang;
                    hsx.Logo   = filename;
                    db.HangSXes.InsertOnSubmit(hsx);
                    db.SubmitChanges();
                }
                return(RedirectToAction("NhaSanXuat"));
            }
            else
            {
                ViewData["loi"] = "Mã hãng này bị trùng";
            }
            return(this.ThemNSX());
        }