コード例 #1
0
ファイル: ManagerController.cs プロジェクト: turr/XinZhiHua
        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);
        }
コード例 #2
0
ファイル: ManagerController.cs プロジェクト: turr/XinZhiHua
        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);
        }