public async Task <List <ObjectResult <T> > > AddsAsync(List <T> entity) { List <ObjectResult <T> > result = new List <ObjectResult <T> >(); foreach (var item in entity) { ObjectResult <T> added = new ObjectResult <T>(); try { using (VideoEntities context = new VideoEntities()) { context.Entry(item).State = EntityState.Added; await context.SaveChangesAsync(); added.obj = item; added.status.OK(); } } catch (Exception ex) { added.obj = item; added.status.Error("Database Error", ex.Message); } result.Add(added); } return(result); }
public ServiceResult Remove(T entity) { ServiceResult result = new ServiceResult(); try { using (VideoEntities context = new VideoEntities()) { context.Entry(entity).State = EntityState.Deleted; context.SaveChanges(); result.OK(); } } catch (Exception ex) { result.Error("Database Error", ex.Message); } return(result); }
public ObjectResult <T> Add(T entity) { ObjectResult <T> result = new ObjectResult <T>(); try { using (VideoEntities context = new VideoEntities()) { context.Entry(entity).State = EntityState.Added; context.SaveChanges(); result.status.OK(); result.obj = entity; } } catch (Exception ex) { result.status.Error("Database Error", ex.Message); } return(result); }
public async Task <ServiceResult> UpdateAsync(T entity) { ServiceResult result = new ServiceResult(); try { using (VideoEntities context = new VideoEntities()) { context.Entry(entity).State = EntityState.Modified; await context.SaveChangesAsync(); result.OK(); } } catch (Exception ex) { result.Error("Database Error", ex.Message); } return(result); }
public object GetVideoUrl(int id, ref int count) { //UpdVideoUrl(id, 999); DataLog dl = new DataLog(); dl.KeyId = id; dl.Type = (int)LogEnum.VIDEOLOG; dl.OpenId = ""; dl.Describe = ""; dl.CreateTime = DateTime.Now; var tempdata = from a in ve.VideoUrl where a.Vid == id orderby a.Sort ascending, a.Id ascending select new { a.Id, a.Source, a.Path, a.TempPath }; foreach (var item in tempdata.ToList()) { string TempPath = item.Path; TempPath = TempPath.Replace("\t", ""); TempPath = TempPath.Replace("\\t", ""); string encryptPath = EncryptHelper.Encrypt(TempPath); if (string.IsNullOrEmpty((item.TempPath + "").Trim()) || (item.TempPath + "").Trim() == "7NTyKCzlI8jyXd7WRF1wFA==" || !encryptPath.Equals((item.TempPath + "").Trim())) //if (string.IsNullOrEmpty((item.TempPath + "").Trim()) || (item.TempPath + "").Trim() == "7NTyKCzlI8jyXd7WRF1wFA==" || item.Source.Trim() == "youku") { //IParsing jx = null; switch (item.Source.Trim()) { //case "youku": // jx = new YouKu(); // break; //case "360": // jx = new Yun360(); // break; //case "qq": // jx = new QQ(); // break; //case "Ku6": //case "ku6": // jx = new Ku6(); // break; //case "QQYun": // TempPath = item.Path.Replace(",", "/,"); // break; //case "myfile": // TempPath = item.Path.Replace(",", "/,"); // break; case "AES_baby": continue; //return item.TempPath; } //if (jx != null) //{ // try // { // TempPath = jx.Parsing(item.Path); // } // catch // { // TempPath = item.Path; // } //} Models.VideoUrl model = new VideoUrl(); model.Id = item.Id; model.TempPath = EncryptHelper.Encrypt(TempPath); DbEntityEntry <VideoUrl> entry = ve.Entry <VideoUrl>(model); entry.State = EntityState.Unchanged; entry.Property("TempPath").IsModified = true; ve.SaveChanges(); } } var data = from a in ve.VideoUrl where a.Vid == id orderby a.Sort ascending, a.Id ascending select new { a.Id, a.State, a.Source, a.Path, a.TempPath }; count = data.Count(); dlh.AddModel(dl); return(data); }