public int Update(ProductModelShow item, int LastUserId, HttpPostedFileBase file, string vid, HttpServerUtilityBase Server, HttpPostedFileBase ContentPic) { try { s26webDataContext db = new s26webDataContext(); var data = db.Product.FirstOrDefault(f => f.Id == item.Id); if (data != null) { data.Content = item.Content; if (file != null) if (file.ContentLength > 0 && file.ContentType.ToLower() == "image/jpeg" || file.ContentType == "image/png") data.PictureLink = Method.Upload_File(file, vid, Server); else data.PictureLink = ""; if (ContentPic != null) if (ContentPic.ContentLength > 0 && ContentPic.ContentType.ToLower() == "image/jpeg" || ContentPic.ContentType == "image/png") data.ContentPic = Method.Upload_File(ContentPic, vid, Server); else data.ContentPic = ""; data.Price = item.Price; data.Point = item.Point; data.Limit = item.Limit; data.Display = item.Display; data.UpdateTime = DateTime.UtcNow; data.LastUserId = LastUserId; data.Link = item.Link; data.Memo = item.Memo; db.SubmitChanges(); db.Connection.Close(); return data.Id; } db.Connection.Close(); return -1; } catch { return -1; } }
//public static NewsConfig Get_Config(int fun_id) //{ // s26webDataContext db = new s26webDataContext(); // var data = db.NewsConfig.FirstOrDefault(f => f.Fun_Id == fun_id); // db.Connection.Close(); // return data == null ? new NewsConfig() : data; //} //public ProductModel(int fun) //{ // Fun_Id = fun; // config = Get_Config(fun); //} //public NewsConfig config = new NewsConfig(); //public string Keyword = ""; //public bool Home_Show = false; //public string Sort = "update"; //public DateTime? create_time_start = null; //public DateTime? create_time_end = null; //public DateTime? update_time_start = null; //public DateTime? update_time_end = null; //public List<int> Cid=new List<int>(); //private int Fun_Id; //public void Clear_Params() //{ // Keyword = ""; // Sort = "update"; // Home_Show = false; // Cid = new List<int>(); // create_time_start = null; // create_time_end = null; // update_time_start = null; // update_time_end = null; //} public List<ProductModelShow> Convert(List<Product> item) { List<ProductModelShow> result = new List<ProductModelShow>(); foreach (var i in item) { var product = new ProductModelShow { Id = i.Id, Name = i.Name, Content = i.Content, PictureLink = i.PictureLink, Price = i.Price, Point = i.Point, Limit = i.Limit, Display = i.Display, CreateTime = i.CreateTime.AddHours(8), UpdateTime = i.UpdateTime.AddHours(8), LastUserId = i.LastUserId, Link = i.Link, Memo = i.Memo, ContentPic = i.ContentPic }; result.Add(product); } return result; }
public ProductModelShow Get_One(int id) { s26webDataContext db = new s26webDataContext(); ProductModelShow data = new ProductModelShow(); try { var item = db.Product.FirstOrDefault(f => f.Id == id); data.Name = item.Name; data.Content = item.Content; data.PictureLink = item.PictureLink; data.Price = item.Price; data.Point = item.Point; data.Limit = item.Limit; data.Display = item.Display; data.CreateTime = item.CreateTime.AddHours(8); data.UpdateTime = item.UpdateTime.AddHours(8); data.Link = item.Link; data.Memo = item.Memo; data.ContentPic = item.ContentPic; db.Connection.Close(); return data; } catch { return null; } }