Esempio n. 1
0
        public string DeleteSanPham(int id)
        {
            var status = "{\"status\":-1, \"sanpham\":" + id + "}";

            try
            {
                Func_SanPham hamsanpham = new Func_SanPham();
                tbl_sanpham  data       = hamsanpham.FindEntity(id);
                if (data.tinhtrang != -1)
                {
                    data.tinhtrang = -1;
                }
                else
                {
                    data.tinhtrang = 1;
                }
                int?ss = hamsanpham.Update(data);

                if (ss != null)
                {
                    status = "{\"status\":1, \"sanpham\":" + id + ", \"color\":" + data.tinhtrang + "}";
                }
                else
                {
                    status = "{\"status\":-1, \"sanpham\":" + id + ", \"color\":1}}";
                }
            }
            catch (Exception ex)
            {
                string er = ex.Message;
                status = "{\"status\":-1, \"sanpham\":" + id + ", \"error\":\"" + er + "\"}";
            }

            return(status);
        }
Esempio n. 2
0
        // Sửa dữ liệu
        public int?Update(tbl_sanpham model)
        {
            tbl_sanpham dbEntry = context.tbl_sanpham.Find(model.id);

            if (dbEntry == null)
            {
                return(null);
            }

            dbEntry.ten          = model.ten;
            dbEntry.gia          = model.gia;
            dbEntry.soluong      = model.soluong;
            dbEntry.trongluong   = model.trongluong;
            dbEntry.ROM          = model.ROM;
            dbEntry.RAM          = model.RAM;
            dbEntry.thenho       = model.thenho;
            dbEntry.camera_truoc = model.camera_truoc;
            dbEntry.camera_sau   = model.camera_sau;
            dbEntry.pin          = model.pin;
            dbEntry.baohanh      = model.baohanh;
            dbEntry.bluetooth    = model.bluetooth;
            dbEntry.id_nsx       = model.id_nsx;
            dbEntry.CPU          = model.CPU;
            dbEntry.manhinh      = model.manhinh;
            dbEntry.tinhtrang    = model.tinhtrang;

            context.SaveChanges();

            return(model.id);
        }
Esempio n. 3
0
        public string GetSanPham(int id)
        {
            Func_SanPham hamsanpham = new Func_SanPham();
            tbl_sanpham  sanpham    = hamsanpham.FindEntity(id);
            sanpham      newsanpham = hamsanpham.getnewsanpham(sanpham);

            string json = JsonConvert.SerializeObject(newsanpham);

            return(json);
        }
Esempio n. 4
0
        // Xóa theo key
        public int?Delete(int MaSP)
        {
            tbl_sanpham dbEntry = context.tbl_sanpham.Find(MaSP);

            if (dbEntry == null)
            {
                return(null);
            }

            context.tbl_sanpham.Remove(dbEntry);
            context.SaveChanges();
            return(MaSP);
        }
Esempio n. 5
0
        // Thêm 1 đối tượng
        public int?Insert(tbl_sanpham model)
        {
            tbl_sanpham dbEntry = context.tbl_sanpham.Find(model.id);

            if (dbEntry != null)
            {
                return(null);
            }

            context.tbl_sanpham.Add(model);
            context.SaveChanges();
            return(model.id);
        }
Esempio n. 6
0
        // Sửa dữ liệu
        public int?Update(tbl_nhasanxuat model)
        {
            tbl_sanpham dbEntry = context.tbl_sanpham.Find(model.id);

            if (dbEntry == null)
            {
                return(null);
            }

            dbEntry.ten = model.ten;
            dbEntry.id  = model.id;


            context.SaveChanges();

            return(model.id);
        }
Esempio n. 7
0
        public tbl_sanpham getsanpham(sanpham oldsanpham)
        {
            tbl_sanpham newsanpham = new tbl_sanpham();

            newsanpham.baohanh      = oldsanpham.baohanh;
            newsanpham.bluetooth    = oldsanpham.bluetooth;
            newsanpham.camera_sau   = oldsanpham.camera_sau;
            newsanpham.camera_truoc = oldsanpham.camera_truoc;
            newsanpham.CPU          = oldsanpham.CPU;
            newsanpham.gia          = oldsanpham.gia;
            newsanpham.id           = oldsanpham.id;
            newsanpham.id_dm        = oldsanpham.id_dm;
            newsanpham.id_nsx       = oldsanpham.id_nsx;
            newsanpham.manhinh      = oldsanpham.manhinh;
            newsanpham.pin          = oldsanpham.pin;
            newsanpham.RAM          = oldsanpham.RAM;
            newsanpham.ROM          = oldsanpham.ROM;
            newsanpham.soluong      = oldsanpham.soluong;
            newsanpham.ten          = oldsanpham.ten;
            newsanpham.thenho       = oldsanpham.thenho;
            newsanpham.tinhtrang    = oldsanpham.tinhtrang;
            newsanpham.trongluong   = oldsanpham.trongluong;
            return(newsanpham);
        }
Esempio n. 8
0
        public string UpdatesSanPham([FromBody] string data)
        {
            //  string data = requestdata.Content.ReadAsStringAsync().Result;
            dynamic stuff = JsonConvert.DeserializeObject(data);

            string status = "{\"status\":1, \"sanpham\":" + stuff.id + "}";

            try
            {
                sanpham      newsanpham = JsonConvert.DeserializeObject <sanpham>(data);
                Func_SanPham hamsanpham = new Func_SanPham();
                tbl_sanpham  sanpham    = hamsanpham.getsanpham(newsanpham);
                int?         x          = hamsanpham.Update(sanpham);
                if (x == null)
                {
                    status = "{\"status\":-1, \"sanpham\":" + stuff.id + "}";
                }
            }
            catch
            {
                status = "{\"status\":0, \"sanpham\":" + stuff.id + "}";
            }
            return(status);
        }
Esempio n. 9
0
        // Trả về 1 đối tượng khi biết khóa
        public tbl_sanpham FindEntity(int MaSP)
        {
            tbl_sanpham dbEntry = context.tbl_sanpham.Find(MaSP);

            return(dbEntry);
        }
Esempio n. 10
0
        public ActionResult AddProduct()
        {
            int?        res  = null;
            tbl_sanpham data = new tbl_sanpham();

            try
            {
                data.ten        = Request["tensp"];
                data.thenho     = Request["thenhosp"];
                data.gia        = Int32.Parse(Request["giasp"]);
                data.trongluong = Request["trongluongsp"];
                data.soluong    = Int32.Parse(Request["soluongsp"]);

                data.ROM          = Request["romsp"];
                data.RAM          = Request["ramsp"];
                data.baohanh      = Request["thoigianbaohanhsp"];
                data.camera_sau   = Request["camerasausp"];
                data.camera_truoc = Request["cameratruocsp"];
                data.CPU          = Request["cpusp"];
                data.manhinh      = Request["manhinhsp"];
                data.pin          = Int32.Parse(Request["pinsp"]);
                data.tinhtrang    = 1;
                data.id_nsx       = Int32.Parse(Request["nhasanxuatsp"]);
                data.bluetooth    = Int32.Parse(Request["bluetoothsp"]);
                HttpPostedFileBase fileUpload = Request.Files["imgsp"];

                Func_SanPham tp = new Func_SanPham();
                res = tp.Insert(data);
                if (res != null)
                {
                    int id = (int)res;

                    if (fileUpload != null)
                    {
                        String timeStamp = GetTimestamp(DateTime.Now);
                        var    fileName  = timeStamp + Path.GetExtension(fileUpload.FileName);


                        var path = Path.Combine(Server.MapPath("~/Content/images"), fileName);
                        // file is uploaded
                        if (System.IO.File.Exists(path))
                        {
                            ViewBag.ThongBao = "Hình ảnh đã tồn tại";
                        }
                        else
                        {
                            Func_Anh installanh = new Func_Anh();
                            tbl_anh  anh        = new tbl_anh();
                            anh.duongdan = fileName;
                            anh.id_sp    = id;

                            int?x = installanh.Insert(anh);
                            if (x == null)
                            {
                                res = -1;
                            }
                            else
                            {
                                fileUpload.SaveAs(path);
                            }
                        }
                    }
                }
            }
            catch
            {
                res = -1;
            }
            if (res != null)
            {
                ViewBag.add = res;
            }
            else
            {
                ViewBag.add = -1;
            }
            return(RedirectToAction("Add", new {
                add = res
            }));
        }