Esempio n. 1
0
        public ActionResult Show(int page = 1)
        {
            string action_name = RouteData.Values["action"].ToString().ToLower();

            ViewBag.Title = "后台管理((产品展示)";

            double page_size = 10;

            INewAndProductService service = new NewAndProductService();
            List <NewAndProduct>  data    = service.Table().Where(M => M.Type.IndexOf(action_name) != -1).ToList();

            ViewBag.AllCount = data.Count();

            double all_page = Math.Ceiling(data.Count() / page_size);

            ViewBag.AllPage = all_page;

            if (page < 1)
            {
                page = 1;
            }
            else if (page > all_page)
            {
                page = (int)all_page;
            }
            ViewBag.NowPage = page;

            List <NewAndProduct> p_data = data.Skip((int)page_size * (page - 1)).Take((int)page_size).OrderBy(M => M.AddTime).ToList();
            string page_data            = data == null ? "" : Newtonsoft.Json.JsonConvert.SerializeObject(p_data);

            ViewBag.Data = page_data;
            return(View());
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            ViewBag.Title = "首页";
            string action_name  = RouteData.Values["action"].ToString().ToLower();
            string page_data    = "";
            string product_data = "";

            try
            {
                ISettingService service = new SettingService();
                List <Setting>  data    = service.Table().Where(M => M.Type.IndexOf(action_name) != -1).ToList();
                page_data = data == null ? "" : Newtonsoft.Json.JsonConvert.SerializeObject(data);

                INewAndProductService product_service = new NewAndProductService();
                List <NewAndProduct>  product         = product_service.Table().Where(M => M.Type == "productedit").Take(3).ToList();
                product_data = product == null ? "" : Newtonsoft.Json.JsonConvert.SerializeObject(product);
            }
            catch
            {
            }
            ViewBag.Data        = page_data;
            ViewBag.ProductData = product_data;

            return(View());
        }
Esempio n. 3
0
 private void DeleteData(int id)
 {
     try
     {
         INewAndProductService service = new NewAndProductService();
         service.Delete(id);
     }
     catch
     {
     }
 }
Esempio n. 4
0
        public ActionResult ShowEdit(int id = 0)
        {
            ViewBag.Title = "后台管理(产品展示|添加/修改)";
            string page_data = "";

            try
            {
                INewAndProductService service = new NewAndProductService();
                NewAndProduct         data    = service.Table().Where(M => M.Id == id).FirstOrDefault();
                page_data = data == null ? "" : Newtonsoft.Json.JsonConvert.SerializeObject(data);
            }
            catch
            {
            }
            ViewBag.Data = page_data;
            return(View());
        }
Esempio n. 5
0
        private int SaveData(string json_data)
        {
            int result = 0;

            var json_obj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(json_data);
            int id       = int.Parse(json_obj["id"].ToString());

            try
            {
                INewAndProductService service = new NewAndProductService();
                NewAndProduct         data    = service.Table().Where(M => M.Id == id).FirstOrDefault();
                if (data == null)
                {
                    data             = new NewAndProduct();
                    data.Title       = json_obj["title"].ToString();
                    data.Content     = json_obj["content"].ToString();
                    data.Detail      = json_obj["detail"].ToString();
                    data.Img         = json_obj["img"].ToString();
                    data.AddTime     = DateTime.Parse(json_obj["add_time"].ToString());
                    data.ProductNo   = json_obj["product_no"].ToString();
                    data.ProductType = json_obj["product_type"].ToString();
                    data.Type        = json_obj["type"].ToString();
                    if (!string.IsNullOrEmpty(data.Title))
                    {
                        service.Insert(data);
                        result = data.Id;
                    }
                }
                else
                {
                    data.Title       = json_obj["title"].ToString();
                    data.Content     = json_obj["content"].ToString();
                    data.Detail      = json_obj["detail"].ToString();
                    data.ProductNo   = json_obj["product_no"].ToString();
                    data.ProductType = json_obj["product_type"].ToString();
                    service.Update(data);
                    result = data.Id;
                }
            }
            catch
            {
            }
            return(result);
        }
Esempio n. 6
0
        public ActionResult ShowDetail(int id = 0)
        {
            string page_data = "";

            try
            {
                INewAndProductService service = new NewAndProductService();
                NewAndProduct         data    = service.Table().Where(M => M.Id == id).FirstOrDefault();
                if (data == null)
                {
                    return(RedirectToAction("Show", "Home"));
                }
                else
                {
                    page_data = Newtonsoft.Json.JsonConvert.SerializeObject(data);
                }
            }
            catch
            {
            }
            ViewBag.Data = page_data;
            return(View());
        }
Esempio n. 7
0
        public bool UploadImg()
        {
            bool result = false;

            try
            {
                string type = Request.QueryString["key"];
                if (!string.IsNullOrEmpty(type))
                {
                    type = type.ToString().ToLower();

                    if (Request.Files.Count > 0)
                    {
                        HttpPostedFileBase f         = Request.Files[0];
                        string             file_name = type + "_" + DateTime.Now.ToString("yyMMddHHmmss") + f.FileName.Substring(f.FileName.LastIndexOf("."));
                        string             path      = "~/Content/Img/";

                        string from = Request.QueryString["from"];
                        if (from != null && from.ToString().ToLower() == "new")
                        {
                            path += "New/";
                        }
                        else if (from != null && from.ToString().ToLower() == "show")
                        {
                            path += "Show/";
                        }
                        else if (from != null && from.ToString().ToLower() == "product")
                        {
                            path += "Product/";
                        }
                        if (Directory.Exists(Request.MapPath(path)) == false)//如果不存在就创建file文件夹
                        {
                            Directory.CreateDirectory(Request.MapPath(path));
                        }
                        var file = Path.Combine(Request.MapPath(path), Path.GetFileName(file_name));
                        f.SaveAs(file);

                        if (from == "new" || from == "show" || from == "product")
                        {
                            int data_id = 0;
                            if (Request.QueryString["dataId"] != null)
                            {
                                int.TryParse(Request.QueryString["dataId"].ToString(), out data_id);
                            }
                            INewAndProductService service  = new NewAndProductService();
                            NewAndProduct         new_data = service.GetByID(data_id);
                            if (new_data != null)
                            {
                                new_data.Img = path + file_name;
                                service.Update(new_data);
                            }
                        }
                        else
                        {
                            ISettingService service = new SettingService();
                            Setting         data    = service.Table().Where(M => M.Type == type).FirstOrDefault();
                            if (data == null)
                            {
                                data         = new Setting();
                                data.Type    = type;
                                data.Content = "";
                                data.Img     = path + file_name;
                                service.Insert(data);
                            }
                            else
                            {
                                data.Img = path + file_name;
                                service.Update(data);
                            }
                        }
                        result = true;
                    }
                }
            }
            catch
            {
            }
            return(result);
        }