Example #1
0
        // Xóa theo key
        public int?Delete(int id)
        {
            tbl_anh dbEntry = context.tbl_anh.Find(id);

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

            context.tbl_anh.Remove(dbEntry);
            context.SaveChanges();
            return(id);
        }
Example #2
0
        // Thêm 1 đối tượng
        public int?Insert(tbl_anh model)
        {
            tbl_anh dbEntry = context.tbl_anh.Find(model.id);

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

            context.tbl_anh.Add(model);
            context.SaveChanges();
            return(model.id);
        }
Example #3
0
        // Sửa dữ liệu
        public int?Update(tbl_anh model)
        {
            tbl_anh dbEntry = context.tbl_anh.Find(model.id);

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

            dbEntry.duongdan = model.duongdan;
            dbEntry.id_sp    = model.id_sp;

            context.SaveChanges();

            return(model.id);
        }
Example #4
0
        // Trả về 1 đối tượng khi biết khóa
        public tbl_anh FindEntity(int id)
        {
            tbl_anh dbEntry = context.tbl_anh.Find(id);

            return(dbEntry);
        }
Example #5
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
            }));
        }