Ejemplo n.º 1
0
        public bool Add(ISetModel setModel, ITopicModel topicModel, byte[] file)
        {
            DataAccessStatus dataAccessStatus = new DataAccessStatus();

            try
            {
                string path = Path.Combine(Base._setsFolder, setModel.SetName);
                if (Directory.Exists(path))
                {
                    return(false);
                }
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);             //Create set folder
                }
                path = Path.Combine(path, topicModel.TopicName); //Change path to /SetName/TopicName
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path); //Create topic folder
                }
                string filename = Path.Combine(path, topicModel.TopicName);
                filename += ".rtf";
                if (!File.Exists(filename))
                {
                    //using(File.Create(filename));
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                    {
                        MemoryStream ms = new MemoryStream(file);
                        ms.WriteTo(fs);
                        fs.Close();
                        ms.Close();
                    }
                }

                path = Path.Combine(path, "Videos");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path); //Create Videos folder
                }
                path = Path.Combine(path, "Thumbnails");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path); //Create Thumbnail folder
                }
                return(true);
            }
            catch (IOException e)
            {
                dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message, customMessage: "Set already exists", stackTrace: e.StackTrace);
                throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
            }
        }
Ejemplo n.º 2
0
 public TopicController()
 {
     _iTopicModel = new TopicModel();
 }