public JsonResult EditThucVat()
        {
            ThucVatViewModel model = new ThucVatViewModel();

            model.ID                  = Int32.Parse(Request.Form["id"]);
            model.TenVietNam          = Request.Form["nameTV"];
            model.TenLaTinh           = Request.Form["nameLT"];
            model.MoTa                = Request.Form["description"];
            model.DoDayLa             = double.Parse(Request.Form["DoDayLa"]);
            model.DoDayVo             = double.Parse(Request.Form["DoDayVo"]);
            model.LuongNuocTrongLa    = double.Parse(Request.Form["LuongNuocTrongLa"]);
            model.LuongNuocTrongVo    = double.Parse(Request.Form["LuongNuocTrongVo"]);
            model.LuongTroThoTrongLa  = double.Parse(Request.Form["LuongTroThoTrongLa"]);
            model.LuongTroThoTrongVo  = double.Parse(Request.Form["LuongTroThoTrongVo"]);
            model.ThoiGianChayTrenLa  = double.Parse(Request.Form["ThoiGianChayTrenLa"]);
            model.ThoiGianChayTrenVo  = double.Parse(Request.Form["ThoiGianChayTrenVo"]);
            model.IDKhaNangSinhTruong = Int32.Parse(Request.Form["growth"]);
            model.IDKhaNangTaiSinh    = Int32.Parse(Request.Form["reborn"]);
            model.IDGiaTriKinhTe      = Int32.Parse(Request.Form["economy"]);
            model.IDHo                = Int32.Parse(Request.Form["IDBo"]);
            model.DuongDanHInhAnh     = UploadImage();

            int result = db.EditThucVat(model);

            if (result == 1)
            {
                return(Json(new { status = "SUCCESS" }));
            }
            else
            {
                return(Json(new { status = "ERROR" }));
            }
        }
Exemple #2
0
 public ActionResult Detail(int id)
 {
     try
     {
         ThucVatViewModel model = db.getListThucVatById(id);
         ViewBag.ListSameGrowth  = db.getAllListThucVat(null).Where(x => x.ID != id && x.IDKhaNangSinhTruong == model.IDKhaNangSinhTruong).Take(3).ToList();
         ViewBag.ListSameEconomy = db.getAllListThucVat(null).Where(x => x.ID != id && x.IDGiaTriKinhTe == model.IDGiaTriKinhTe).ToList();
         return(View(model));
     }
     catch
     {
         return(new HttpNotFoundResult("optional description"));
     }
 }
        public int EditThucVat(ThucVatViewModel model)
        {
            try
            {
                int?       IDHInhAnh  = db.Tb_ThucVat.Where(x => x.ID == model.ID).First().IDHInhAnh;
                Tb_HinhAnh tb_HinhAnh = db.Tb_HinhAnh.Find(IDHInhAnh);
                if (model.DuongDanHInhAnh != null)
                {
                    tb_HinhAnh.DuongDan = model.DuongDanHInhAnh;
                    db.SaveChanges();
                }


                Tb_ThucVat tb_ThucVat = db.Tb_ThucVat.Find(model.ID);
                tb_ThucVat.TenLaTinh           = model.TenLaTinh;
                tb_ThucVat.TenVietNam          = model.TenVietNam;
                tb_ThucVat.MoTa                = model.MoTa;
                tb_ThucVat.IDGiaTriKinhTe      = model.IDGiaTriKinhTe;
                tb_ThucVat.IDKhaNangSinhTruong = model.IDKhaNangSinhTruong;
                tb_ThucVat.IDKhaNangTaiSinh    = model.IDKhaNangTaiSinh;
                tb_ThucVat.IDHo                = model.IDHo;
                tb_ThucVat.DoDayLa             = model.DoDayLa;
                tb_ThucVat.DoDayVo             = model.DoDayVo;
                tb_ThucVat.LuongNuocTrongLa    = model.LuongNuocTrongLa;
                tb_ThucVat.LuongNuocTrongVo    = model.LuongNuocTrongVo;
                tb_ThucVat.LuongTroThoTrongLa  = model.LuongTroThoTrongLa;
                tb_ThucVat.LuongTroThoTrongVo  = model.LuongTroThoTrongVo;
                tb_ThucVat.ThoiGianChayTrenLa  = model.ThoiGianChayTrenLa;
                tb_ThucVat.ThoiGianChayTrenVo  = model.ThoiGianChayTrenVo;
                db.SaveChanges();
                return(1);
            }
            catch
            {
                return(0);
            }
        }
        public int AddThucVat(ThucVatViewModel model)
        {
            try
            {
                Tb_HinhAnh tb_HinhAnh = new Tb_HinhAnh();
                tb_HinhAnh.DuongDan = model.DuongDanHInhAnh;
                db.Tb_HinhAnh.Add(tb_HinhAnh);
                db.SaveChanges();
                db.Tb_ThucVat.Add(new Tb_ThucVat()
                {
                    TenLaTinh           = model.TenLaTinh,
                    TenVietNam          = model.TenVietNam,
                    MoTa                = model.MoTa,
                    IDGiaTriKinhTe      = model.IDGiaTriKinhTe,
                    IDKhaNangSinhTruong = model.IDKhaNangSinhTruong,
                    IDKhaNangTaiSinh    = model.IDKhaNangTaiSinh,
                    IDHInhAnh           = tb_HinhAnh.ID,
                    IDHo                = model.IDHo,
                    DoDayLa             = model.DoDayLa,
                    DoDayVo             = model.DoDayVo,
                    LuongNuocTrongLa    = model.LuongNuocTrongLa,
                    LuongNuocTrongVo    = model.LuongNuocTrongVo,
                    LuongTroThoTrongLa  = model.LuongTroThoTrongLa,
                    LuongTroThoTrongVo  = model.LuongTroThoTrongVo,
                    ThoiGianChayTrenLa  = model.ThoiGianChayTrenLa,
                    ThoiGianChayTrenVo  = model.ThoiGianChayTrenVo
                });

                db.SaveChanges();
                return(1);
            }
            catch
            {
                return(0);
            }
        }