public ViewResult Search(SearchViewModel viewModel) { viewModel.Properties = UnitOfWork.GetRepository<Property>().Get(); var stateService = new PropertyStateService(UnitOfWork); var propertyStates = viewModel.States .Select(pair => stateService.GetState(pair.Key, pair.Value)) .Where(propertyState => propertyState != null) .ToList(); var searchService = new SearchService(UnitOfWork); viewModel.Packages = searchService.FindPackageWithSamePropertyStates(propertyStates); return View(viewModel); }
public ActionResult Upload(UploadViewModel viewModel) { viewModel.Properties = UnitOfWork.GetRepository<Property>().Get(); if (!ModelState.IsValid) { return View(viewModel); } var package = new ContentPackage(); package.PropertyStates = new Collection<PropertyState>(); package.Files = new Collection<ContentFile>(); package.Description = viewModel.Description; package.Caption = viewModel.Caption; package.Price = viewModel.Price; package.Owner = CurrentUser; ImportFilesToPackage(package, viewModel.PreviewContentFiles, true); ImportFilesToPackage(package, viewModel.ContentFiles, false); var service = new PropertyStateService(UnitOfWork); var specifiedStates = viewModel.States.Where(pair => !string.IsNullOrEmpty(pair.Value)); foreach (var pair in specifiedStates) { //получаем состояние или создаем новое если не существет var propertyState = service.GetState(pair.Key, pair.Value); if (propertyState == null) { var property = UnitOfWork.GetRepository<Property>().GetByID(pair.Key); propertyState = service.CreateState(property, pair.Value); } package.PropertyStates.Add(propertyState); } _fileStorageManager.Store(package); UnitOfWork.GetRepository<ContentPackage>().Insert(package); UnitOfWork.Save(); return InformationView("Загрузка завершена", "Контент успешно загружен. Благодарим за использование нашего ресурса.", new ActionLinkInfo("Content", "Upload", "Вернуться")); }
public JsonResult UpdateStates(Dictionary<int,string> states,int id) { var specifieStatePairs = states.Where(pair => !string.IsNullOrEmpty(pair.Value)); var response = GetDefaultStates(); if (specifieStatePairs.Count() == 0) return Json(response.Properties.Single(x => x.ID == id).States); var properties = UnitOfWork.GetRepository<Property>().Get(); var service = new PropertyStateService(UnitOfWork); foreach (var statePair in specifieStatePairs) { var state = service.GetState(statePair.Key, statePair.Value); var property = properties.First(x => x.ID == statePair.Key); foreach (var prop in properties.Where(x => x.Order > property.Order)) { IEnumerable<PropertyState> propertyStates = new Collection<PropertyState>(); if (state != null) propertyStates = service.GetBoundedStates(prop, state); var joinedStates = string.Join(STATE_VALUES_SEPARATOR, propertyStates.Select(st => st.Value)); var existingProperty = response.Properties.Single(x => x.ID == prop.ID); response.Properties.Remove(existingProperty); response.Properties.Add(new PropertyViewModel {ID = prop.ID, States = joinedStates}); } } return Json(response.Properties.Single(x => x.ID == id).States); }
public void GetState_StateNotExists_NullReturned() { // Arrange var unitOfWork = new UnitOfWorkMock(); var propertyStateService = new PropertyStateService(unitOfWork); var property = CreateProperty(); // Act var state = propertyStateService.GetState(property.ID, "value"); // Assert state.Should().BeNull(); }
public void GetState_StateExists_StateReturned() { // Arrange var unitOfWork = new UnitOfWorkMock(); var propertyStateService = new PropertyStateService(unitOfWork); var property = CreateProperty(); var propertyState = CreatePropertyState(property); unitOfWork.GetRepository<PropertyState>().Insert(propertyState); unitOfWork.Save(); // Act var state = propertyStateService.GetState(property.ID, propertyState.Value); // Assert state.Should().Be(propertyState); }
public void GetState_PropertyNotExists_NullReturned() { // Arrange var unitOfWork = new UnitOfWorkMock(); var propertyStateService = new PropertyStateService(unitOfWork); var property = CreateProperty(); var propertyState = CreatePropertyState(property); unitOfWork.GetRepository<PropertyState>().Insert(propertyState); // Act var state = propertyStateService.GetState(2, "value"); // Assert state.Should().BeNull(); }