public IActionResult Create(SliderUploadVM SliderUploadVM, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (file == null || file.Length == 0)
            {
                return(BadRequest("Your file was not valid!"));
            }
            using (Stream stream = file.OpenReadStream())
            {
                using (BinaryReader br = new BinaryReader(stream))
                {
                    var fileContent = br.ReadBytes((int)file.Length);
                    SliderUploadVM.Image = SaveFileHelper.SaveFileToDisk(_env, fileContent, file.FileName, file.ContentType);
                }
            }
            Slider _newSlider = Mapper.Map <Slider>(SliderUploadVM);

            _sliderRepository.Add(_newSlider);
            _sliderRepository.SaveChanges();

            CreatedAtRouteResult result = CreatedAtRoute("GetCategory", new { controller = "Categories", id = SliderUploadVM.Id }, SliderUploadVM);

            return(result);
        }
        public IActionResult Update(SliderUploadVM SliderUploadVM, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (file != null)
            {
                using (Stream stream = file.OpenReadStream())
                {
                    using (BinaryReader br = new BinaryReader(stream))
                    {
                        var fileContent = br.ReadBytes((int)file.Length);
                        SliderUploadVM.Image = SaveFileHelper.SaveFileToDisk(_env, fileContent, file.FileName, file.ContentType);
                    }
                }
            }

            Slider _sliderDb = _sliderRepository.GetSingle(SliderUploadVM.Id);

            if (_sliderDb == null)
            {
                return(NotFound());
            }

            Mapper.Map(SliderUploadVM, _sliderDb);

            _sliderRepository.SaveChanges();

            return(new NoContentResult());
        }
        public IActionResult Create(ContentUploadVM ContentUploadVM, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (file != null)
            {
                using (Stream stream = file.OpenReadStream())
                {
                    using (BinaryReader br = new BinaryReader(stream))
                    {
                        var fileContent = br.ReadBytes((int)file.Length);
                        ContentUploadVM.Image = SaveFileHelper.SaveFileToDisk(_env, fileContent, file.FileName, file.ContentType);
                    }
                }
            }


            Content _newContent = Mapper.Map <Content>(ContentUploadVM);

            _contentRepository.Add(_newContent);
            _contentRepository.SaveChanges();

            CreatedAtRouteResult result = CreatedAtRoute("GetContent", new { controller = "Content", id = ContentUploadVM.Id }, ContentUploadVM);

            return(result);
        }
Exemplo n.º 4
0
        public void JsonSaveSucceeds()
        {
            var SUT = new SaveFileHelper();

            SUT.SaveModuleDataJson("Z:\\Test.json", new List <ISavableModuleData>()
            {
                new SavableModuleData()
                {
                    ModuleName       = "TestName",
                    ModuleTypeName   = "TestModuleType",
                    ModuleSaveString = "1 2 3"
                }
            }, new Dictionary <string, List <string> >());
        }
        private void btnSensorsType_Click(object sender, EventArgs e)
        {
            checkedListBoxSensorsType.Items.Clear();
            String sensorsTypeStr = null;

            try
            {
                SensorDataService1Client sensorDataService1Client = new SensorDataService1Client();
                sensorsTypeStr = sensorDataService1Client.getSensorsType();
                sensorDataService1Client.Close();

                if (sensorsTypeStr == null || sensorsTypeStr.Length == 0)
                {
                    MessageBox.Show("无可用传感器,或者Android设备未连上Service!", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else
                {
                    //保存Android传感器类型到文件
                    SaveFileHelper.SaveFile(sensorsTypeStr, MainForm.baseFilePath + "\\SensorsType.txt");

                    string[] sensorsTypeArr = sensorsTypeStr.Split(',');
                    for (int i = 1; i < sensorsTypeArr.Length; i++)
                    {
                        string[] sensorsTypeItemArr = sensorsTypeArr[i].Split(':');
                        if (androidSensorsTypeSet.Contains((SensorType)(int.Parse(sensorsTypeItemArr[0]))))
                        {
                            continue;
                        }
                        else
                        {
                            sensorsTypeDict.Add(sensorsTypeItemArr[1], (SensorType)(int.Parse(sensorsTypeItemArr[0])));
                            androidSensorsTypeSet.Add((SensorType)(int.Parse(sensorsTypeItemArr[0])));
                        }
                    }
                    foreach (string sensorName in sensorsTypeDict.Keys)
                    {
                        checkedListBoxSensorsType.Items.Add(sensorName);
                    }

                    buttonOK.Enabled = true;
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("查询失败,可能服务未启动", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                Debug.WriteLine("Er" + e1.ToString());
            }
        }
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();

            fileDialog.RestoreDirectory = true;
            fileDialog.InitialDirectory = baseFilePath;
            fileDialog.Filter           = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            fileDialog.FileName         = filename.Substring(1, filename.Length - 1);
            fileDialog.RestoreDirectory = true;

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                SaveFileHelper.SaveFile(sensorDataTable.SensorsTable, fileDialog.FileName);
            }
        }
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SaveFileHelper.SaveFile(sensorDataTable.SensorsTable, baseFilePath + filename);
 }