public void MessageMap() { Specification <PublisherModel> specification = s => s .Member(m => m.Name, m => m .NotEmpty().WithMessage("The field is empty").WithExtraMessage("Error in Name field") .MinLength(3).WithMessage("The field is too short").WithExtraMessage("Error in Name field") ) .Member(m => m.CompanyId, m => m .NotEmpty().WithMessage("The field is empty").WithExtraMessage("Error in CompanyId field") .NotContains("company").WithMessage("Company Id cannot contain 'company' word") .NotContains("id").WithCode("ID_IN_COMPANY") ) .Rule(m => m.Name is null || m.CompanyId is null) .WithMessage("All members must be present"); var validator = Validator.Factory.Create(specification); var publisher = new PublisherModel() { Name = "", CompanyId = "some_id" }; var result = validator.Validate(publisher); result.MessageMap["Name"].Should().Contain(new[] { "The field is empty", "Error in Name field", "The field is too short", "Error in Name field" }); result.MessageMap["Name"].Where(n => n == "Error in Name field").Should().HaveCount(2); result.MessageMap[""].Should().ContainSingle("All members must be present"); result.Paths.Contains("CompanyId").Should().BeTrue(); result.MessageMap.Keys.Contains("CompanyId").Should().BeFalse(); result.CodeMap.Keys.Contains("CompanyId").Should().BeTrue(); }
public void Codes() { Specification <PublisherModel> specification = s => s .Member(m => m.Name, m => m .NotEmpty().WithCode("EMPTY_FIELD").WithExtraCode("NAME_ERROR") .MinLength(3).WithCode("SHORT_FIELD").WithExtraCode("NAME_ERROR") ) .Member(m => m.CompanyId, m => m .NotEmpty().WithCode("EMPTY_FIELD").WithExtraCode("COMPANYID_ERROR") .NotContains("ID").WithCode("ID_IN_CONTENT") ) .Rule(m => m.Name != m.CompanyId).WithCode("SAME_VALUES"); var validator = Validator.Factory.Create(specification); var publisher = new PublisherModel() { Name = "", CompanyId = "" }; var result = validator.Validate(publisher); result.Codes.Should().HaveCount(5); result.Codes.Should().Contain("EMPTY_FIELD", "NAME_ERROR", "SHORT_FIELD", "COMPANYID_ERROR", "SAME_VALUES"); }
public void CodeMap() { Specification <PublisherModel> specification = s => s .Member(m => m.Name, m => m .NotEmpty().WithCode("EMPTY_FIELD").WithExtraCode("NAME_ERROR") .MinLength(3).WithCode("SHORT_FIELD").WithExtraCode("NAME_ERROR") ) .Member(m => m.CompanyId, m => m .NotEmpty().WithCode("EMPTY_FIELD").WithExtraCode("COMPANYID_ERROR") .NotContains("company").WithCode("COPANY_IN_CONTENT") .NotContains("id").WithMessage("Invalid company value") ) .Rule(m => m.Name is null || m.CompanyId is null).WithCode("NULL_MEMBER"); var validator = Validator.Factory.Create(specification); var publisher = new PublisherModel() { Name = "", CompanyId = "some_id" }; var result = validator.Validate(publisher); result.CodeMap["Name"].Should().Contain(new[] { "EMPTY_FIELD", "NAME_ERROR", "SHORT_FIELD", "NAME_ERROR" }); result.CodeMap["Name"].Where(n => n == "NAME_ERROR").Should().HaveCount(2); result.CodeMap[""].Should().ContainSingle("NULL_MEMBER"); result.Paths.Contains("CompanyId").Should().BeTrue(); result.CodeMap.Keys.Contains("CompanyId").Should().BeFalse(); result.MessageMap.Keys.Contains("CompanyId").Should().BeTrue(); }
public async Task <PublisherModel> UpdatePublisher(PublisherModel publisherModel, [ScopedService] LibraryDbContext context) { context.Publishers.Update(publisherModel); await context.SaveChangesAsync(); return(publisherModel); }
protected virtual void UpdateLocales(Publisher publisher, PublisherModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(publisher, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(publisher, x => x.Description, localized.Description, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(publisher, x => x.MetaKeywords, localized.MetaKeywords, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(publisher, x => x.MetaDescription, localized.MetaDescription, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(publisher, x => x.MetaTitle, localized.MetaTitle, localized.LanguageId); //search engine name var seName = publisher.ValidateSeName(localized.SeName, localized.Name, false); _urlRecordService.SaveSlug(publisher, seName, localized.LanguageId); } }
public virtual ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePublishers)) { return(AccessDeniedView()); } var model = new PublisherModel(); //locales AddLocales(_languageService, model.Locales); //templates PrepareTemplatesModel(model); //ACL PrepareAclModel(model, null, false); //Stores PrepareStoresMappingModel(model, null, false); //default values model.PageSize = _catalogSettings.DefaultPublisherPageSize; model.PageSizeOptions = _catalogSettings.DefaultPublisherPageSizeOptions; model.Published = true; model.AllowCustomersToSelectPageSize = true; return(View(model)); }
public async Task <IActionResult> PutPublisherModel(int id, PublisherModel publisherModel) { if (id != publisherModel.PublisherId) { return(BadRequest()); } _context.Entry(publisherModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublisherModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <PublisherModel> > PostPublisherModel(PublisherModel publisherModel) { _context.Publishers.Add(publisherModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPublisherModel", new { id = publisherModel.PublisherId }, publisherModel)); }
public async Task <BaseResponseMessage> UpdatePublisher(PublisherModel publisher) { var newPublisher = _mapper.Map <Publisher>(publisher); var response = new BaseResponseMessage(); var publisherToUpdate = await _publisherRepository.GetPublisher(newPublisher.Id); if (publisherToUpdate == null) { response.RawData = $"Publisher with {newPublisher.Id} wasn't found."; return(response); } if (newPublisher.Equals(publisherToUpdate)) { response.RawData = $"Publisher {newPublisher.Name} already existing with similar data."; return(response); } await _publisherRepository.UpdatePublisher(newPublisher); response.Id = newPublisher.Id; return(response); }
public ActionResult GetDetails(string key) { PublisherModel model = _publisherService.GetModelByCompanyName(key); var viewModel = Mapper.Map <PublisherViewModel>(model); return(View(viewModel)); }
protected void Button2_Click(object sender, EventArgs e) { PublisherModel publisher = new PublisherModel(TextBox3.Text); Response.Write(PublisherBLL.AddPublisher(publisher)); Label2.Text = PublisherBLL.GetPublisherCount().ToString(); }
public SearchModel Result(string searchKey) { SearchModel model = new SearchModel(); List <AuthorSearchModel> authors = new List <AuthorSearchModel>(); List <BookSearchModel> books = new List <BookSearchModel>(); List <PublisherModel> publishers = new List <PublisherModel>(); List <CategoryTagAssigment> entity = _categoryTagAssignment.Search(searchKey); foreach (var item in entity) { AuthorSearchModel author = new AuthorSearchModel(); BookSearchModel book = new BookSearchModel(); PublisherModel publisher = new PublisherModel(); author.Id = item.AuthorId; author.Name = item.AuthorName + " " + item.AuthorSurname; book.Id = item.BookId; book.Name = item.BookName; publisher.Id = item.PublisherId; publisher.Name = item.PublisherName; authors.Add(author); books.Add(book); publishers.Add(publisher); } model.Authors = authors.GroupBy(x => x.Id).Select(x => x.First()).ToList(); model.Books = books.GroupBy(x => x.Id).Select(x => x.First()).ToList(); model.Publishers = publishers.GroupBy(x => x.Name).Select(x => x.First()).ToList(); return(model); }
protected virtual void SavePublisherAcl(Publisher publisher, PublisherModel model) { publisher.SubjectToAcl = model.SelectedCustomerRoleIds.Any(); var existingAclRecords = _aclService.GetAclRecords(publisher); var allCustomerRoles = _customerService.GetAllCustomerRoles(true); foreach (var customerRole in allCustomerRoles) { if (model.SelectedCustomerRoleIds.Contains(customerRole.Id)) { //new role if (existingAclRecords.Count(acl => acl.CustomerRoleId == customerRole.Id) == 0) { _aclService.InsertAclRecord(publisher, customerRole.Id); } } else { //remove role var aclRecordToDelete = existingAclRecords.FirstOrDefault(acl => acl.CustomerRoleId == customerRole.Id); if (aclRecordToDelete != null) { _aclService.DeleteAclRecord(aclRecordToDelete); } } } }
public List <PublisherUiModel> AlphabeticalList() { List <PublisherUiModel> responseModel = new List <PublisherUiModel>(); List <PublisherModel> alphabeticList = new List <PublisherModel>(); var list = _publisher.GetList().ToList(); var groupedByLetter = from letter in Letters join service in list on letter equals service.Name[0] into grouped select new { Letter = letter, list = grouped }; foreach (var entry in groupedByLetter) { alphabeticList = new List <PublisherModel>(); PublisherUiModel UiModel = new PublisherUiModel(); UiModel.Character = entry.Letter.ToString(); foreach (var service in entry.list) { PublisherModel model = new PublisherModel(); model.Name = service.Name; model.Id = service.Id; alphabeticList.Add(model); } if (alphabeticList.Count > 0) { UiModel.AlphabeticalList = alphabeticList; responseModel.Add(UiModel); } } return(responseModel); }
public void Add(PublisherModel model) { var publisher = Mapper.Map <Publisher>(model); _unitOfWork.PublisherRepository.Insert(publisher); _unitOfWork.SaveChanges(); }
protected virtual void SaveStoreMappings(Publisher publisher, PublisherModel model) { publisher.LimitedToStores = model.SelectedStoreIds.Any(); var existingStoreMappings = _storeMappingService.GetStoreMappings(publisher); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { if (model.SelectedStoreIds.Contains(store.Id)) { //new store if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) { _storeMappingService.InsertStoreMapping(publisher, store.Id); } } else { //remove store var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) { _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } } }
public async Task <IActionResult> Edit(PublisherModel model) { Publisher publisher = await _publisherService.GetPublisherById(model.Id); if (publisher == null) { return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { try { publisher = _mapper.Map <PublisherModel, Publisher>(model, publisher); publisher = await _publisherService.UpdatePublisher(publisher); return(RedirectToAction(nameof(Details), new { id = publisher.Id })); } catch (Exception exc) { ModelState.AddModelError("", exc.Message); return(View(model)); } } return(View(model)); }
public void GetGames_BasicTest() { // Arrange var publisherId = _fixture.Create <int>(); var consoleId = _fixture.Create <int>(); _fixture.Customize <GameModel>(x => x .With(y => y.PublisherId, publisherId) // Assign all games to testPublisher .Without(y => y.PublisherName) ); var testGames = _fixture.CreateMany <GameModel>(); var testPublisher = new PublisherModel() { PublisherId = publisherId, PublisherName = _fixture.Create <string>() }; var testConsole = new ConsoleModel() { ConsoleId = consoleId, ConsoleName = _fixture.Create <string>() }; var gameDbSet = CreateDbSetMock(testGames); var publisherDbSet = CreateDbSetMock(new List <PublisherModel>() { testPublisher }); var consoleDbSet = CreateDbSetMock(new List <ConsoleModel>() { testConsole }); var genreDbSet = CreateDbSetMock(new List <GenreModel> { }); // Empty as we're not testing this var gameGenreDbSet = CreateDbSetMock(new List <GameGenreModel> { }); // Same _videoGameContextMock.Setup(x => x.Games).Returns(gameDbSet.Object); _videoGameContextMock.Setup(x => x.Publishers).Returns(publisherDbSet.Object); _videoGameContextMock.Setup(x => x.Consoles).Returns(consoleDbSet.Object); _videoGameContextMock.Setup(x => x.Genres).Returns(genreDbSet.Object); _videoGameContextMock.Setup(x => x.GamesGenres).Returns(gameGenreDbSet.Object); // Act var gameResults = _gameRepo.GetGames(); // Assert Assert.AreEqual(testGames.Count(), gameResults.Count()); for (int i = 0; i < testGames.Count(); i++) { var testGame = testGames.ElementAt(i); var gameResult = gameResults.ElementAt(i); Assert.AreEqual(testGame.GameId, gameResult.GameId); Assert.AreEqual(testGame.GameName, gameResult.GameName); Assert.AreEqual(testGame.PublisherId, gameResult.PublisherId); Assert.AreEqual(testPublisher.PublisherName, gameResult.PublisherName); } }
public ActionResult EditPublisher(int id, PublisherModel publisher) { ViewBag.Title = "Library :: Редакирование роли"; ViewBag.Caption = "Редактирование издателя"; if (ModelState.IsValid) { pRepo.GetOne(id).Name = publisher.Name; BookModel book = bRepo.GetAll().ToList().Find(_book => _book.Publisher?.Name == publisher.Name); while (book != null) { book.Publisher.Name = publisher.Name; book = bRepo.GetAll().ToList().Find(_book => _book.Publisher?.Name == publisher.Name); } return(RedirectToAction("EditPublisher", new { id = publisher.Id })); } else { ViewBag.NameError = "Не менее 2 символов; Цифры не допустимы."; ViewBag.Publisher = publisher; return(View("PublisherForm", publisher)); } }
public ViewResult CreatePublisher() { ViewBag.Title = "Library :: Издатели"; ViewBag.Caption = "Создать издателя"; PublisherModel newPublisher = new PublisherModel(); return(View("PublisherForm", newPublisher)); }
public IHttpActionResult CreatePublisher(PublisherModel model) { var publisher = Mapper.Map <PublisherModel, PublisherDTO>(model); _publisherService.Create(publisher); return(Ok("Publisher created")); }
public JsonResult Delete(PublisherModel model) { Response <PublisherModel> responseSaving = JsonConvert.DeserializeObject <Response <PublisherModel> >(UiRequestManager.Instance.Post("Publisher", "Save", JsonConvert.SerializeObject(model))); return(Json(new ResultJson { Message = responseSaving.Message, Success = responseSaving.IsSuccess })); }
public IEnumerable <GameModel> GetGamesByPublisher(PublisherModel publisherModel) { Publisher publisher = _unitOfWork.PublisherRepository.GetById(publisherModel.PublisherId); IEnumerable <Game> games = _unitOfWork.GameRepository.GetAll().Where(g => g.Publisher == publisher); var gameModels = Mapper.Map <IEnumerable <GameModel> >(games); return(gameModels); }
public void ShouldMapEntityToModel() { Publisher entity = _publisherFixtures.GetEntity(); PublisherModel model = _mapper.Mapper.Map <PublisherModel>(entity); model.Id.Should().Be(entity.Id); model.Name.Should().Be(entity.Name); }
[HttpPost]/*, ValidateAntiForgeryToken]*/ public ActionResult PublisherSave(PublisherModel model) { if (ModelState.IsValid && SortMainObject.CheckUserHasWriteAccess(model.SortMainId)) { model.Save(); } return(null); }
public void ShouldMapModelToEntity() { PublisherModel model = _publisherFixtures.GetModel(); Publisher entity = _mapper.Mapper.Map <Publisher>(model); entity.Id.Should().Be(model.Id); entity.Name.Should().Be(model.Name); }
public async Task <PublisherModel> DeletePublisher(int id, [ScopedService] LibraryDbContext context) { PublisherModel publisherModel = await context.Publishers.FindAsync(id); context.Publishers.Remove(publisherModel); await context.SaveChangesAsync(); return(publisherModel); }
public static int InsertPublisher(PublisherModel publisher) { string sql = "insert into publisher values(@name)"; return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter[] { new SqlParameter("name", publisher.name) })); }
public async Task <IReadOnlyList <PublicationModel> > GetPublications(PublisherModel publisherModel, PublicationByIdDataLoader dataLoader, [ScopedService] LibraryDbContext context, CancellationToken cancellationToken) { int[] publicationIds = await context.Publications .Where(x => x.PublisherId == publisherModel.Id) .Select(x => x.Id) .ToArrayAsync(); return(await dataLoader.LoadAsync(publicationIds, cancellationToken)); }
public IHttpActionResult EditPublisher(int id, PublisherModel model) { var publisher = Mapper.Map <PublisherModel, PublisherDTO>(model); publisher.Id = id; _publisherService.Edit(publisher); return(Ok("Publisher edited")); }