public string AddChefStar(dynamic requestData) { try { string addChefStar = JsonConvert.SerializeObject(requestData); ChefStar model = JsonConvert.DeserializeObject <ChefStar>(addChefStar); if (model.Introduce.IndexOf("base64") > 0) { string d = model.Introduce; foreach (string a in imgHandel.GetHtmlImageUrlList(d)) { if (a.IndexOf(ImgHandle.DNS) < 0) { string[] asplit = a.Split(','); string imgtype = asplit[0].Substring(11, asplit[0].Length - 18); string filepath = imgHandel.Base64StringToImage(asplit[1], imgtype, "/pic/Dishtutor"); d = d.Replace(a, filepath); } } model.Introduce = d; } model.UpdateTime = DateTime.Now; model.UpdatePerson = model.CreatePerson; db.ChefStar.Add(model); db.SaveChanges(); return(model.ChefStarId.ToString()); } catch (Exception) { return("No"); } }
public string UpdateChefStar(dynamic requestData) { try { string chefStar = JsonConvert.SerializeObject(requestData); ChefStar model = JsonConvert.DeserializeObject <ChefStar>(chefStar); var q = (from v in db.ChefStar where v.ChefStarId == model.ChefStarId select v).FirstOrDefault(); q.ChefStarName = model.ChefStarName; q.ChefStarPosition = model.ChefStarPosition; q.CityName = model.CityName; q.HeadPicUrl = model.HeadPicUrl; q.HotelName = model.HotelName; if (model.Introduce.IndexOf("base64") > 0) { string d = model.Introduce; foreach (string a in imgHandel.GetHtmlImageUrlList(d)) { if (a.IndexOf(ImgHandle.DNS) < 0) { string[] asplit = a.Split(','); string imgtype = asplit[0].Substring(11, asplit[0].Length - 18); string filepath = imgHandel.Base64StringToImage(asplit[1], imgtype, "/pic/Dishtutor"); d = d.Replace(a, filepath); } } model.Introduce = d; } q.Introduce = model.Introduce; q.UpdateTime = DateTime.Now; q.UpdatePerson = model.UpdatePerson; q.IsDisplay = model.IsDisplay; q.PriorityId = model.PriorityId; q.PicUrl = model.PicUrl; model.ChefStarId = 0; db.Entry <ChefStar>(q).State = EntityState.Modified; db.SaveChanges(); return("OK"); } catch (Exception) { return("No"); } }