public TrackStepViewModel AddTrack(SamplePlayer samplePlayer) { var track = new Track(samplePlayer); Tracks.Add(track); var trackVm = new TrackStepViewModel(track); try { if (CurrentTrackViewModel != null) { var index = TrackViewModels.IndexOf(CurrentTrackViewModel); if (index != -1) { TrackViewModels.Insert(index + 1, trackVm); return(trackVm); } } } catch (ArgumentOutOfRangeException) { } TrackViewModels.Add(trackVm); return(trackVm); }
public void Create_PostData_CheckWrongFormatGeo() { var image1 = new Mock <HttpPostedFileBase>(); image1.Setup(f => f.ContentLength).Returns(1); image1.Setup(f => f.FileName).Returns("myFileName1.jpg"); var image2 = new Mock <HttpPostedFileBase>(); image2.Setup(f => f.ContentLength).Returns(1); image2.Setup(f => f.FileName).Returns("myFileName2.jpg"); List <HttpPostedFileBase> images = new List <HttpPostedFileBase>() { image1.Object, image2.Object }; var geoFile = new Mock <HttpPostedFileBase>(); geoFile.Setup(f => f.ContentLength).Returns(1); geoFile.Setup(f => f.FileName).Returns("myFileName3.jpg"); TrackViewModels track = new TrackViewModels() { Name = "ThisIsTestName", Description = "ThisIsTestDescription" }; var result = _controller.Create(track, images, geoFile.Object); Assert.IsTrue(_controller.ViewData.ModelState.Count == 1); Assert.IsTrue(_controller.ViewData.ModelState.Keys.Contains("WrongFormatGeo")); }
public void Create_GetView_ItsOkViewModelIsTrackView() { var mockTrack = new Mock <IService <Track> >(); var mockUser = new Mock <IService <User> >(); TrackController controller = new TrackController(mockUser.Object, mockTrack.Object); TrackViewModels expected = new TrackViewModels(); PartialViewResult result = controller.Create() as PartialViewResult; var actual = result.Model; Assert.AreEqual(expected, actual); }
public void Create_PostData_CheckWhithoutImages() { TrackViewModels track = new TrackViewModels() { Name = "ThisIsTestName", Description = "ThisIsTestDescription" }; var result = _controller.Create(track, null, null); Assert.IsTrue(_controller.ViewData.ModelState.Count == 1); Assert.IsTrue(_controller.ViewData.ModelState.Keys.Contains("NoImage")); }
public ActionResult Edit(long id, TrackViewModels trackVM, IEnumerable <HttpPostedFileBase> fileData, HttpPostedFileBase kmlfile) { try { // TODO: Add update logic here return(RedirectToAction("Index")); } catch { return(View()); } }
private void ReadFromJson(string jsonData) { var saveService = new PersistencyService(); saveService.CreateDataFromJsonProject(AudioDefines.XAudio, AudioDefines.WaveFormat, AudioDefines.VoicePool, jsonData); MasterPan = saveService.MasterTrackPan; MasterVolume = saveService.MasterTrackVolume; MasterBpm = saveService.MasterTrackBpm; Tracks = new ConcurrentBag <Track>(saveService.Tracks); TrackViewModels.Clear(); foreach (var track in Tracks) { TrackViewModels.Add(new TrackStepViewModel(track)); } if (TrackViewModels.Any()) { CurrentTrackViewModel = TrackViewModels.First(); } }
public void Create_PostData_ItIsOkModel() { var image1 = new Mock <HttpPostedFileBase>(); image1.Setup(f => f.ContentLength).Returns(1); image1.Setup(f => f.FileName).Returns("myFileName.jpg"); var image2 = new Mock <HttpPostedFileBase>(); image2.Setup(f => f.ContentLength).Returns(1); image2.Setup(f => f.FileName).Returns("myFileName.jpg"); List <HttpPostedFileBase> images = new List <HttpPostedFileBase>() { image1.Object, image2.Object }; TrackViewModels track = new TrackViewModels() { Name = "ThisIsTestName", Description = "ThisIsTestDescription" }; var result = _controller.Create(track, images, null); Assert.IsTrue(_controller.ViewData.ModelState.Count == 0); }
public ActionResult Create(TrackViewModels trackVM, IEnumerable <HttpPostedFileBase> images, HttpPostedFileBase geoFile) { try { if (ModelState.IsValid) { // var kmlfile = fileData.Last(); if (_trackService.GetItemList().FirstOrDefault(track => track.Name == trackVM.Name) == null) { var config = new MapperConfiguration(cfg => cfg.CreateMap <TrackViewModels, Track>()); var mapper = config.CreateMapper(); var trackModel = mapper.Map <TrackViewModels, Track>(trackVM); if (geoFile != null) { System.IO.FileInfo file = new System.IO.FileInfo(geoFile.FileName); if (file.Extension == ".gpx" || file.Extension == ".kml") { string fname = file.Name.Remove((file.Name.Length - file.Extension.Length)); fname = fname + file.Extension; // fname = fname + System.DateTime.Now.ToString("_ddMMyyhhmmssms") + file.Extension; geoFile.SaveAs(Server.MapPath("../Content/Tracks/" + fname)); trackModel.TrackKml = fname; } else { ModelState.AddModelError("WrongFormatGeo", "Разрешенные только следующие форматы гео-файлов : gpx, kml"); return(PartialView(trackVM)); } } if (images != null) { images = images.Where(f => f != null); foreach (var someFile in images) { System.IO.FileInfo file = new System.IO.FileInfo(someFile.FileName); if (file.Extension == ".jpeg" || file.Extension == ".jpg" || file.Extension == ".png" || file.Extension == ".gif" || file.Extension == ".bmp") { string fname = file.Name.Remove((file.Name.Length - file.Extension.Length)); fname = fname + System.DateTime.Now.ToString("_ddMMyyhhmmssms") + file.Extension; someFile.SaveAs(Server.MapPath("../Content/Images/" + fname)); Picture pic = new Picture { Name = fname, Path = Server.MapPath("../Content/Images/" + fname), }; trackModel.Pictures.Add(pic); } else { ModelState.AddModelError("WrongFormatImages", "Разрешенные только следующие форматы изображений : jpeg, jpg, png, gif, bmp"); return(PartialView(trackVM)); } } } else { ModelState.AddModelError("NoImage", "Не выбрано не одного фото"); return(PartialView(trackVM)); } _trackService.Create(trackModel); _trackService.Save(); return(RedirectToAction("Edit", "Track", new { id = trackModel.Id })); } else { ModelState.AddModelError("DoubleTrack", "Маршрут с таким названием уже существует"); return(PartialView(trackVM)); } } else { ModelState.AddModelError("ModelEror", ""); return(PartialView(trackVM)); } } catch { return(PartialView(trackVM)); } return(PartialView(trackVM)); }