// // CUSTOM FUNCTION // public bool UploadFile(int userId, object data, out Library.DTO.Notification notification) { List <DTO.OnlineFile> files = ((Newtonsoft.Json.Linq.JArray)data).ToObject <List <DTO.OnlineFile> >(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (OnlineFileMngEntities context = CreateContext()) { foreach (DTO.OnlineFile dtoFile in files) { OnlineFile dbFile = new OnlineFile(); context.OnlineFile.Add(dbFile); dbFile.UpdatedBy = userId; dbFile.UpdatedDate = DateTime.Now; converter.DTO2DB(dtoFile, ref dbFile, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId); } context.SaveChanges(); } return(true); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (OnlineFileMngEntities context = CreateContext()) { // check if can delete OnlineFile dbItem = context.OnlineFile.FirstOrDefault(o => o.OnlineFileID == id); if (dbItem == null) { throw new Exception("File not found"); } // everything ok, delete // remove attached file if (!string.IsNullOrEmpty(dbItem.FileUD)) { fwFactory.RemoveFile(dbItem.FileUD); } context.OnlineFile.Remove(dbItem); context.OnlineFilePermission.Local.Where(o => o.OnlineFile == null).ToList().ForEach(o => context.OnlineFilePermission.Remove(o)); context.SaveChanges(); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } return(true); }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.OnlineFile dtoFile = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.OnlineFile>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (OnlineFileMngEntities context = CreateContext()) { OnlineFile dbItem = context.OnlineFile.FirstOrDefault(o => o.OnlineFileID == id); if (dbItem == null) { notification.Message = "File not found!"; return(false); } else { dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; converter.DTO2DB(dtoFile, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }