public ActionResult Details(int?id)
        {
            // nếu id = null trở về trang chủ
            if (id == null || id < 1)
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                Loai loai = db.Loais
                            .Include(p => p.ChungLoai)
                            .SingleOrDefault(p => p.LoaiID == id);

                if (loai == null)
                {
                    throw new Exception("Loại ID: " + id + " Không tồn tại!");
                }
                return(View(loai));
            }
            catch (Exception ex)
            {
                object cauBaoLoi = "Lỗi truy cập dữ liệu.<br/>" + ex.Message;
                return(View("Error", cauBaoLoi));//pt6
            }
        }
 public ActionResult DeleteConfirmed(int id)
 {
     try {
         Loai loai = db.Loais.Find(id);
         db.Loais.Remove(loai);
         db.SaveChanges();
         //huỷ thành công, điều hướng về action index của controller hiện hành
         //--> điều hướng về trang danh sách loại
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         object cauBaoLoi = "Lỗi truy cập dữ liệu.<br/>";
         int    d         = db.SanPhams.Count(p => p.LoaiID == id);
         if (d > 0)
         {
             cauBaoLoi += "Vì đã có thông tin về sản phẩm liên quan ";
         }
         else
         {
             cauBaoLoi += ex.Message;
         }
         return(View("Error", cauBaoLoi));//pt6
     }
 }
 [ValidateAntiForgeryToken]// chống mạo danh
 public ActionResult Create(Loai loai)
 {
     try
     {
         Loai l = db.Loais.SingleOrDefault(p => p.Ten == loai.Ten);
         if (l != null)
         {
             ModelState.AddModelError("Ten", "Tên thiết bị này đã tồn tại.");
         }
         if (ModelState.IsValid)
         {
             //trường hợp dữ liệu nhập hợp lệ(không vi phạm các kiểm tra cài đặt trong data model)
             loai.BiDanh = XuLyDuLieu.LoaiBoDauTiengViet(loai.Ten);
             db.Loais.Add(loai);
             db.SaveChanges();
             // lưu thành công
             //điều hướng về action Index của controller điều hành
             return(RedirectToAction("Index"));
         }
         //trường hợp dữ liệu nhập không hợp lệ
         //quay trở lại view và chuyền lại  dữ liệu
         List <ChungLoai> chungLoaiItems = db.ChungLoais.ToList();
         ViewBag.ChungLoaiID = new SelectList(db.ChungLoais, "ChungLoaiID", "Ten", loai.ChungLoaiID);
         return(View(loai));
     }
     catch (Exception ex)
     {
         object cauBaoLoi = "lưu thông tin không thành công.<br/>" + ex.Message;
         return(View("Error", cauBaoLoi));//pt6
     }
 }
 public ActionResult Edit([Bind(Include = "LoaiID,Ten,ChungLoaiID,BiDanh")] Loai loai)
 {
     try
     {
         if (ModelState.IsValid)
         {
             int d = db.Loais.Count(p => p.LoaiID != loai.LoaiID && p.Ten == loai.Ten);
             if (d > 0)
             {
                 ModelState.AddModelError("Ten", "Tên thiết bị này đã tồn tại.");
             }
             //trường hợp dữ liệu nhập hợp lệ(không vi phạm các kiểm tra cài đặt trong data model)
             loai.BiDanh          = XuLyDuLieu.LoaiBoDauTiengViet(loai.Ten);
             db.Entry(loai).State = EntityState.Modified;
             db.SaveChanges();
             // lưu thành công
             //điều hướng về action Index của controller điều hành
             return(RedirectToAction("Index"));
         }
         //trường hợp dữ liệu nhập không hợp lệ
         //quay trở lại view và chuyền lại  dữ liệu
         List <ChungLoai> chungLoaiItems = db.ChungLoais.ToList();
         ViewBag.ChungLoaiID = new SelectList(db.ChungLoais, "ChungLoaiID", "Ten", loai.ChungLoaiID);
         return(View(loai));
     }
     catch (Exception ex)
     {
         object cauBaoLoi = "cập nhật không thành công.<br/>" + ex.Message;
         return(View("Error", cauBaoLoi));//pt6
     }
 }
Example #5
0
        public async Task <IHttpActionResult> Xoa(int id)
        {
            try
            {
                Loai entity = await db.Loais.FindAsync(id);

                if (entity == null)
                {
                    return(BadRequest($"Loại ID={id} không tồn tại."));
                }

                db.Loais.Remove(entity);
                await db.SaveChangesAsync();

                return(Ok($"Đã xóa thông tin của chủng loại ID={id} thành công."));
            }
            catch (Exception ex)
            {
                int d = await db.HangHoas.CountAsync(p => p.LoaiID == id);

                if (d > 0)
                {
                    return(BadRequest($"Không xóa được vì đã có {d} mặt hàng phụ thuộc."));
                }
                return(BadRequest($"Hiệu chỉnh Không thành công. {ex.Message}"));
            }
        }
Example #6
0
        public async Task <IActionResult> Edit(string id, [Bind("MaLoai,GioiTinh,TenLoai")] Loai loai)
        {
            if (id != loai.MaLoai)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(loai);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoaiExists(loai.MaLoai))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(loai));
        }
Example #7
0
        public ActionResult NewBrand(Loai loai)
        {
            if (Session["user"] == null)
            {
                return(RedirectToAction("Login"));
            }

            ViewBag.ChungLoaiID = new SelectList(db.Loais.Where(result => !result.ChungLoaiID.HasValue), "ID", "Ten");
            var countBrand = db.Loais.Count(result => result.Ten.Equals(loai.Ten));

            if (countBrand > 0)
            {
                ModelState.AddModelError("Ten", "Tên loại bị trùng");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var chungLoaiId = Convert.ToInt32(Request["ChungLoaiID"]);
                    loai.ChungLoaiID = chungLoaiId;
                    loai.BiDanh      = XuLyDuLieu.LoaiBoDauTiengViet(loai.Ten);
                    db.Loais.Add(loai);
                    db.SaveChanges();
                    TempData["Success_Mess"] = "<script>alert('Thêm loại mới thành công')</script>";
                    return(View(loai));
                }
                catch (Exception ex)
                {
                    TempData["Error_Mess"] = "<script>alert(Thêm không thành công do'" + ex.Message + "')</script>";
                    return(View(loai));
                }
            }
            return(View(loai));
        }
Example #8
0
        public ActionResult EditBrand(Loai loai)
        {
            if (Session["user"] == null)
            {
                return(RedirectToAction("Login"));
            }

            var countBrand = db.Loais.Count(result => result.Ten.Equals(loai.Ten));

            if (countBrand > 0)
            {
                ModelState.AddModelError("Ten", "Tên loại bị trùng");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var chungLoaiId = Convert.ToInt32(Request["ChungLoaiID"]);
                    loai.ChungLoaiID     = chungLoaiId;
                    loai.BiDanh          = XuLyDuLieu.LoaiBoDauTiengViet(loai.Ten);
                    db.Entry(loai).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["Success_Mess"] = "<script>alert('Cập nhật thành công')</script>";
                    return(View(loai));
                }

                catch (Exception ex)
                {
                    TempData["Error_Mess"] = "<script>alert(Update không thành công do'" + ex.Message + "')</script>";
                    return(View(loai));
                }
            }
            return(View(loai));
        }
Example #9
0
        public ActionResult NewCat(Loai loai)
        {
            if (Session["user"] == null)
            {
                return(RedirectToAction("Login"));
            }

            var cat = db.Loais.Count(result => result.Ten.Equals(loai.Ten));

            if (cat > 0)
            {
                ModelState.AddModelError("Ten", "Tên chủng loại bị trùng");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    loai.BiDanh = XuLyDuLieu.LoaiBoDauTiengViet(loai.Ten);
                    db.Loais.Add(loai);
                    db.SaveChanges();
                    TempData["Success_Mess"] = "<script>alert('Thêm chủng loại mới thành công')</script>";
                    return(View(new Loai()));
                }

                catch (Exception ex)
                {
                    object message = "Không thêm được do" + ex.Message;
                    return(View("Error", message));
                }
            }
            return(View(new Loai()));
        }
Example #10
0
 public dynamic Upload(IFormCollection form)
 {
     try
     {
         //Map từ formcollection sang Loai
         var lo = new Loai();
         if (form.Any())
         {
             if (form.Keys.Contains("tenLoai"))
             {
                 lo.TenLoai = form["tenLoai"];
             }
             if (form.Keys.Contains("moTa"))
             {
                 lo.TenLoai = form["moTa"];
             }
         }
         //xử lý uplaod hình
         foreach (var file in form.Files)
         {
             UploadFile(file);
         }
         //lo.Hinh = form.Files[0].FileName;
         //a.png;b.png;c.jpg
         lo.Hinh = string.Join(";", form.Files.Select(p => p.FileName));
         _context.Add(lo);
         _context.SaveChanges();
         return(new { Success = true });
     }
     catch (Exception ex)
     {
         return(new { Success = false, ex.Message });
     }
 }
Example #11
0
        public async Task <IActionResult> Edit(int id, [Bind("MaLoai,TenLoai,MaLoaiCha")] Loai loai)
        {
            if (id != loai.MaLoai)
            {
                return(NotFound());
            }


            try
            {
                _context.Update(loai);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LoaiExists(loai.MaLoai))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));

            ViewData["MaLoaiCha"] = new SelectList(_context.Loais, "MaLoai", "TenLoai", loai.MaLoaiCha);
            return(View(loai));
        }
Example #12
0
        public bool UpdateLoai(int idTK, int id, string ten)
        {
            Loai nsx = db.Loais.Find(id);

            if (db.Loais.Any(i => i.TenLoai == ten && i.MaLoai != nsx.MaLoai && i.Flag == true))
            {
                return(false);
            }
            else
            {
                string chiTiet = "Đã SỬA ";

                Log log = new Log();
                log.Ngay      = DateTime.Now;
                log.HanhDong  = "SLoai";
                log.KHId      = idTK;
                log.KhachHang = db.KhachHangs.Find(idTK);
                if (nsx.TenLoai != ten)
                {
                    chiTiet     = chiTiet + "'TÊN LOẠI' từ " + nsx.TenLoai + " sang " + ten;
                    nsx.TenLoai = ten;
                }
                if (chiTiet != "Đã SỬA ")
                {
                    log.ChiTiet = chiTiet;
                    db.Logs.Add(log);
                }
                db.SaveChanges();
                return(true);
            }
        }
Example #13
0
        //Chuyển một file Dll phù hợp thành một thể hiện nhân vật
        public static ChucNang The_hien_Chuc_Nang(string Tap_tin)
        {
            ChucNang cn = new ChucNang();

            //Nạp thông tin của một file Dll vào
            //Do đã kiểm tra phần mở rộng là Dll
            //Muốn tìm hiểu về Assembly->MSDN
            Assembly asm = Assembly.LoadFile(Tap_tin);

            //Một asm sẽ chứa nhiều kiểu(Type) khác nhau
            //Duyệt qua từng kiểu(Type) trong tập hợp kiểu(asm.GetTypes())
            foreach (Type Loai in asm.GetTypes())
            {
                //Chọn kiểu mà có chứa giao diện Interface mà chúng ta đã cài đặt trước
                //Điều này rất quan trọng nếu bạn ko kiểm tra sẽ xảy ra lỗi
                Type Loai_Interface = Loai.GetInterface("IChucNang.IChucNang", true);
                if (Loai_Interface != null)//Có Interface phù hợp
                {
                    //Phần quan trọng nhất là ở đây
                    //asm.GetType(Loai_nhan_vat.ToString()) : Lấy kiểu từ một chuỗi
                    //Activator.CreateInstance : Tạo thể hiện từ một kiểu chi định
                    //Vì đã kiểm tra Loai_Interface nên ta có thể ép kiểu ở đây
                    cn.Chucnang = (IChucNang.IChucNang)Activator.CreateInstance(asm.GetType(Loai.ToString()));
                }
            }

            return(cn);
        }
Example #14
0
        public ActionResult Delete(FormCollection form)
        {
            int  id   = Convert.ToInt32(form["id"]);
            Loai loai = data.Loais.SingleOrDefault(i => i.IDLoai == id);

            //Nếu nhóm tồn tại
            if (loai != null)
            {
                //Xóa nhóm
                data.Loais.DeleteOnSubmit(loai);
                try
                {
                    data.SubmitChanges();
                }
                catch (Exception ex)
                {
                    int countLoai = data.Loais.Count(i => i.IDLoai == id);
                    ViewBag.IsError = true;
                    if (ex.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint"))
                    {
                        ViewBag.ErrorBody = string.Format("Không thể xóa loại [{0}] do có {1} món ăn trong loại này.", loai.TenLoai, countLoai);
                    }
                    else
                    {
                        ViewBag.ErrorBody = ex.ToString();
                    }
                    List <Loai> all = data.Loais.ToList();
                    return(View("Index", all));
                }
            }
            //Xóa thành công hoặc nhóm k tồn tại thì trở về Index
            return(RedirectToAction("Index", "AdminLoai"));
        }
Example #15
0
        private void dgvLoai_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string maLoai  = dgvLoai.Rows[e.RowIndex].Cells[0].Value.ToString();
            string tenLoai = dgvLoai.Rows[e.RowIndex].Cells[1].Value.ToString();
            string moTa    = "";

            if (dgvLoai.Rows[e.RowIndex].Cells[2]
                .Value != null)
            {
                moTa = dgvLoai.Rows[e.RowIndex].Cells[2]
                       .Value.ToString();
            }


            Loai suaLoai = new Loai()
            {
                MaLoai  = int.Parse(maLoai),
                MoTa    = moTa,
                TenLoai = tenLoai
            };
            Loai chiTietLoai = _Estore20Db.Loais.FirstOrDefault(item => item.MaLoai == suaLoai.MaLoai);

            chiTietLoai.TenLoai = suaLoai.TenLoai;
            chiTietLoai.MoTa    = suaLoai.MoTa;
            _Estore20Db.SubmitChanges();
            // cập nhật danh sách
            dgvLoai.DataSource = _Estore20Db.Loais.ToList();
        }
Example #16
0
        public async Task <IActionResult> Edit(int id, [Bind("IDLoai,TieuDe,NgayTao,IDNguoiTao")] Loai loai)
        {
            if (id != loai.IDLoai)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(loai);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoaiExists(loai.IDLoai))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(loai));
        }
Example #17
0
        public ActionResult XnxoaHang(int id)
        {
            Loai loai = db.Loais.SingleOrDefault(n => n.MaLoai == id);

            try
            {
                if (loai == null)
                {
                    Response.StatusCode = 404;
                    return(null);
                }
                else
                {
                    db.Loais.DeleteOnSubmit(loai);
                    db.SubmitChanges();
                    ViewBag.Thongbao1 = "Đã Xóa Thành Công";
                }
            }
            catch
            {
                ViewBag.Thongbao1 = "Đã có nước hoa của loại này trong danh sách";
            }

            return(RedirectToAction("LoaiNuochoa"));
        }
Example #18
0
        public IActionResult Create(Loai lo)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (lo.MoTa == null)
            {
                lo.MoTa = "";
            }
            if (lo.Hinh == null)
            {
                lo.Hinh = "";
            }

            int result = LoaiDAO.AddLoai(lo);

            if (result == 0)//thất bại
            {
                return(View());
            }
            //chuyển tới màn hình Edit loại
            return(RedirectToAction("Edit", new { id = result }));
        }
Example #19
0
        // GET: PhieuGiaoNhan/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                id = 0;
            }
            PhieuGiaoNhan               phieuGiaoNhan            = db.PhieuGiaoNhan.Find(id);
            List <List <string> >       chiTietLoai              = new List <List <string> >();
            List <ChiTietPhieuGiaoNhan> listChiTietPhieuGiaoNhan = Model.Database.SelectChiTietPhieuGiaoNhan(id ?? default(int));

            foreach (ChiTietPhieuGiaoNhan ct in listChiTietPhieuGiaoNhan)
            {
                ThietBi tb   = Model.Database.SelectThietBiByMa(ct.MaThietBi);
                Loai    loai = (from l in db.Loai
                                where l.MaLoai == tb.MaLoai
                                select l).FirstOrDefault();
                TinhTrang tt = (from t in db.TinhTrang
                                where t.MaTinhTrang == ct.TinhTrang
                                select t).FirstOrDefault();
                chiTietLoai.Add((new string[] { tb.MaThietBi.ToString(), loai.TenLoai, loai.DonGia.ToString(), loai.ThongSoKyThuat, loai.NamSanXuat, tt.TenTinhTrang }).ToList());
            }
            ViewBag.ChiTietLoai = chiTietLoai;
            if (phieuGiaoNhan == null)
            {
                return(HttpNotFound());
            }
            return(View(phieuGiaoNhan));
        }
        public ActionResult Edit(int?id)
        {
            // nếu id = null trở về trang chủ
            if (id == null || id < 1)
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                Loai loai = db.Loais.Find(id);

                if (loai == null)
                {
                    throw new Exception("Loại ID: " + id + " Không tồn tại!");
                }
                List <ChungLoai> chungLoaiItem = db.ChungLoais.ToList();
                ViewBag.ChungLoaiID = new SelectList(chungLoaiItem, "ChungLoaiID", "Ten");

                return(View(loai));
            }
            catch (Exception ex)
            {
                object cauBaoLoi = "Lỗi truy cập dữ liệu.<br/>" + ex.Message;
                return(View("Error", cauBaoLoi));//pt6
            }
        }
Example #21
0
        public IActionResult Create(Loai loai)
        {
            int maLoaiThem = loaiDAL.AddLoai(loai);

            //return Redirect($"/Loai/Edit/{maLoaiThem}");
            return(RedirectToAction("Loai", "Edit", new { id = maLoaiThem }));
        }
Example #22
0
        public async Task <IHttpActionResult> HieuChinh(LoaiInput input)
        {
            try
            {
                Loai loai = await db.Loais.FindAsync(input.ID);

                if (loai == null)
                {
                    return(BadRequest($"Loại ID ={input.ID} không tồn tại"));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                int d = await db.Loais.CountAsync(p => p.ID != input.ID && (p.MaLoai.StartsWith(input.MaLoai) || input.MaLoai.StartsWith(p.MaLoai)));

                if (d > 0)
                {
                    return(BadRequest($"Mã loại ='{input.MaLoai}' đã có hoặc lồng nhau."));
                }

                loai.MaLoai      = input.MaLoai;
                loai.TenLoai     = input.TenLoai;
                loai.ChungLoaiID = input.ChungLoaiID;

                await db.SaveChangesAsync();

                return(Ok("Hiệu chỉnh thành công"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"Hiệu chỉnh không thành công {ex.Message}"));
            }
        }
Example #23
0
        public ActionResult Create(FormCollection form)
        {
            string tenLoai = form["TenLoai"];
            int    idNhom  = Convert.ToInt32(form["IDNhom"]);
            string alias   = form["LoaiAlias"];

            if (string.IsNullOrWhiteSpace(tenLoai))
            {
                ViewBag.MessageFail = "Tên loại không hợp lệ";
                return(View());
            }

            Loai loai = new Loai();

            loai.TenLoai   = tenLoai;
            loai.IDNhom    = idNhom;
            loai.SoLuong   = 0;
            loai.LoaiAlias = alias;

            if (ModelState.IsValid)
            {
                data.Loais.InsertOnSubmit(loai);
                data.SubmitChanges();
            }
            ViewBag.MessageSuccess = "Thêm loại: [" + tenLoai + "] thành công";
            return(View());
        }
        public JsonResult Create(int id, string TenLoai)
        {
            //Khai báo 1 đối tượng
            Loai obj = new Loai();

            //Gán giá trị
            obj.Id      = id;
            obj.TenLoai = TenLoai;
            if (id > 0)//TH sửa
            {
                obj.Id = id;
                //Lấy đối tượng cũ
                Loai objid = DataProvider.ShopEntities.Loais.Where(p => p.Id == id).First();

                DataProvider.ShopEntities.Entry(objid).CurrentValues.SetValues(obj);
            }
            else
            {
                //Thực hiện thêm và lưu sự thay đổi
                DataProvider.ShopEntities.Loais.Add(obj);
            }

            DataProvider.ShopEntities.SaveChanges();
            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
Example #25
0
        public override bool SaveData()
        {
            DateTime time = DateTime.Now.ServerNow();

            lstEdited.ToList().ForEach(x =>
            {
                Loai gioiTinh        = (Loai)rlokGioiTinh.GetDataSourceRowByKeyValue(x.IDGioiTinh) ?? new Loai();
                eTinhThanh tinhThanh = (eTinhThanh)rlokTinhThanh.GetDataSourceRowByKeyValue(x.IDTinhThanh) ?? new eTinhThanh();

                x.GioiTinh  = gioiTinh.Ten;
                x.TinhThanh = tinhThanh.Ten;

                if (x.KeyID > 0)
                {
                    x.NguoiCapNhat    = clsGeneral.curPersonnel.KeyID;
                    x.MaNguoiCapNhat  = clsGeneral.curPersonnel.Ma;
                    x.TenNguoiCapNhat = clsGeneral.curPersonnel.Ten;
                    x.NgayCapNhat     = time;
                }
                else
                {
                    x.NguoiTao    = clsGeneral.curPersonnel.KeyID;
                    x.MaNguoiTao  = clsGeneral.curPersonnel.Ma;
                    x.TenNguoiTao = clsGeneral.curPersonnel.Ten;
                    x.NgayTao     = time;
                }
            });

            Tuple <bool, List <eKhachHang> > Res = clsFunction.Post("khachhang", lstEdited.ToList());

            return(Res.Item1);
        }
Example #26
0
        public static void DocFileDanhMuc()
        {
            StreamReader reader;

            try
            {
                if (!File.Exists(StringValue.FILE_DANH_MUC))
                {
                    File.Create(StringValue.FILE_DANH_MUC).Close();
                }

                reader = new StreamReader(StringValue.FILE_DANH_MUC);
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] data = line.Split('|');
                    Loai     loai = new Loai();
                    loai.ma     = int.Parse(data[0]);
                    loai.ten    = data[1];
                    loai.tongSL = int.Parse(data[2]);
                    ThemLoaiSanPham(loai);
                    line = reader.ReadLine();
                }
                reader.Close();
            }
            catch
            {
                Console.WriteLine(StringValue.THONG_BAO_LOI_2);
            }
        }
Example #27
0
        public async Task <ActionResult <Loai> > PostLoai(Loai loai)
        {
            _context.Loai.Add(loai);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLoai", new { id = loai.MaLoai }, loai));
        }
Example #28
0
 // GET: Products/ByFactory
 public ActionResult ByFactory(int?id, int page = 1)
 {
     DangTruyVan = Loai.NhaSanXuat;
     if (!id.HasValue)
     {
         return(RedirectToAction("Index", "Home"));
     }
     using (ModelEntities ctx = new ModelEntities())
     {
         ViewBag.CatID = id;
         int soPhanTu             = 4;
         List <tbl_SanPhams> list = ctx.tbl_SanPhams.Where(p => p.NhaSanXuatID == id && p.DaXoa == false && p.TinhTrang == true).ToList();
         Poco_Product_Page   item = new Poco_Product_Page();
         int soTrang = PhanTrang(list.Count, soPhanTu);
         item.DanhSachSanPham = list.Skip((page - 1) * soPhanTu).Take(soPhanTu).ToList();
         item.SoPage          = PhanTrang(list.Count, soPhanTu);
         item.CurPage         = page;
         item.MaSanPham       = id.Value;
         ViewBag.Pages        = item.SoPage;
         ViewBag.CurPage      = page;
         ViewBag.NextPage     = page + 1;
         ViewBag.NextPage     = page - 1;
         if (list.FirstOrDefault() != null)
         {
             int LSPID = list.First().LoaiSanPhamID.Value;
             item.TenLoaiSanPham = ctx.tbl_LoaiSanPhams.First(p => p.LoaiSanPhamID == LSPID).TenLoaiSanPham;
         }
         else
         {
             item.TenLoaiSanPham = string.Empty;
         }
         item.TenNhaSanXuat = ctx.tbl_NhaSanXuats.FirstOrDefault(p => p.NhaSanXuatID == id.Value).TenNhaSanXuat;
         return(View(item));
     }
 }
Example #29
0
        public async Task <IActionResult> PutLoai([FromRoute] int id, [FromBody] Loai loai)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != loai.MaLoai)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #30
0
        public ActionResult sua(string id, HttpPostedFileBase fileUpLoad, FormCollection c)
        {
            int t = int.Parse(id);

            Session["l"] = id;
            Loai s = db.Loais.SingleOrDefault(n => n.maLoai == t);

            ViewBag.MaLoai = new SelectList(db.Loais.ToList().OrderBy(n => n.tenloai), "maLoai", "tenloai");
            ViewBag.MaNhom = new SelectList(db.Nhoms.ToList().OrderBy(n => n.tenNhom), "maNhom", "tenNhom");
            //ViewBag.MaNCC = new SelectList(db.nhaCungCaps.ToList().OrderBy(n => n.tenNCC), "maNCC", "tenNCC");
            if (fileUpLoad == null)
            {
            }
            if (ModelState.IsValid)
            {
                s.maNhom = int.Parse(c["MaNhom"]);
                //s.maLoai = int.Parse(c["txtMaLoai"]);
                s.tenloai = c["txtTenLoai"];

                //if (fileUpLoad != null)
                //{
                //    var fileName = Path.GetFileName(fileUpLoad.FileName);
                //    var path = Path.Combine(Server.MapPath("~/Content"), fileName);
                //    fileUpLoad.SaveAs(path);
                //    s.hinhanhdaidien = fileName;
                //}
                UpdateModel(s);
                db.SubmitChanges();
            }
            return(RedirectToAction("TrangQuanLyLoai", "QuanLyLoai"));
        }
Example #31
0
 public static void Clear(Loai loai,string key)
 {
     switch (loai)
     {
         case Loai.Redis:
             using (var client = new RedisClient(CacheManager.RedisAddress))
             {
                 var redis = client.As<DanhMuc>();
                 var list = redis.Lists[key];
                 list.RemoveAll();
             }
             break;
         case Loai.Cache:
             Cache.Remove(key);
             break;
     }
 }
 public bool ThemLoai(string TenLoai)
 {
     Loai loai = new Loai();
     loai.TenLoai = TenLoai;
     try
     {
         using (DBGiayDepEntities db = new DBGiayDepEntities())
         {
             db.Loais.Add(loai);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return false;
     }
 }