コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Zhytyk/pi52_vpvkr
        private void AddBookBtn_Click(object sender, RoutedEventArgs e)
        {
            InitDataSource(ref bookItems, Mapper.BooksToBookViewModels, bookController.Get);

            AddBook addBook = new AddBook(
                sectionItems   = InitItems(ref sectionItems, Mapper.SectionsToSectionViewModels, sectionController.Get),
                publisherItems = InitItems(ref publisherItems, Mapper.PublishersToPublisherViewModels, publisherController.Get)
                );

            if (addBook.ShowDialog().Value)
            {
                string             name        = addBook.Name.Text;
                string             description = addBook.Description.Text;
                Models.Condition   condition   = (Models.Condition)Enum.Parse(typeof(Models.Condition), addBook.Condition.Text);
                SectionViewModel   sectionVM   = addBook.SelectedSectionItem;
                PublisherViewModel publisherVM = addBook.SelectedPublisherItem;

                if (name != null && sectionVM != null && publisherVM != null)
                {
                    Models.Section section   = sectionController.GetById(sectionVM.Id);
                    Publisher      publisher = publisherController.GetById(publisherVM.Id);
                    Book           book      = new Book(name, description, condition, section, publisher);
                    bookController.Add(book);
                    bookItems.Add(Mapper.BookToBookViewModel(book));
                    return;
                }
            }
        }
コード例 #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(PublisherViewModel model)
        {
            var publisher = _publisherService.GetPublisher(model.Id);

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

            if (ModelState.IsValid)
            {
                publisher.Name        = model.Name;
                publisher.Description = model.Description;
                publisher.CountryId   = model.CountryId;


                var result = _publisherService.UpdatePublisher(publisher);

                model.Id = publisher.Id;

                if (result.Succedeed)
                {
                    return(Json(model));
                }

                return(NotFound(result));
            }
            return(PartialView(model));
        }
コード例 #3
0
        public async Task SavePublisherInsertSuccess_Test()
        {
            PublisherViewModel model = new PublisherViewModel()
            {
                Id      = 0,
                Name    = "abc",
                Address = "123",
                Phone   = "123456789",
                Email   = "*****@*****.**",
                Enabled = true
            };

            var efRepository         = new EfRepository <Publishers>(_dbContext);
            var savePublisherCommand = new SavePublisherCommand(efRepository);
            var result = await savePublisherCommand.ExecuteAsync(model);

            var getListPublisher = new GetListPublisherQuery(efRepository);
            var publisher        = (await getListPublisher.ExecuteAsync()).FirstOrDefault();

            Assert.Equal(result.Data, model.Id);
            Assert.Equal(model.Name, publisher.Name);
            Assert.Equal(model.Address, publisher.Address);
            Assert.Equal(model.Phone, publisher.Phone);
            Assert.Equal(model.Email, publisher.Email);
            Assert.Equal(model.Enabled, publisher.Enabled);
        }
コード例 #4
0
        public async Task <IActionResult> GetPublisher([FromRoute] string id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var publisher = await _context.Publishers.FindAsync(id);

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

            var model = new PublisherViewModel()
            {
                Id          = publisher.Id,
                Name        = publisher.Name,
                Description = publisher.Description,
                Url         = publisher.Url,
                Category    = publisher.Category,
                Language    = publisher.Language,
                Country     = publisher.Country
            };

            return(Ok(model));
        }
コード例 #5
0
        public async Task <IActionResult> DeletePublisher([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var publisher = _iPublisherService.FindBy(F => F.Id == id);

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

            var pub = publisher.SingleOrDefault();

            pub.Deleted = true;
            _iPublisherService.Update(pub);

            PublisherViewModel pvm = new PublisherViewModel();

            pvm.Id   = pub.Id;
            pvm.Name = pvm.Name;

            return(Ok(pvm));
        }
コード例 #6
0
        public async Task SavePublisherUpdateSuccess_Test()
        {
            Publishers publisher1 = new Publishers()
            {
                Id      = 1,
                Name    = "abc",
                Address = "123",
                Phone   = "123456789",
                Email   = "*****@*****.**"
            };

            _dbContext.Set <Publishers>().Add(publisher1);

            PublisherViewModel model = new PublisherViewModel()
            {
                Id      = 1,
                Name    = "abc123",
                Address = "123",
                Phone   = "123456789",
                Email   = "*****@*****.**"
            };

            await _dbContext.SaveChangesAsync();

            var efRepository         = new EfRepository <Publishers>(_dbContext);
            var savePublisherCommand = new SavePublisherCommand(efRepository);
            var result = await savePublisherCommand.ExecuteAsync(model);

            var getListPublisher = new GetListPublisherQuery(efRepository);
            var Publisher        = (await getListPublisher.ExecuteAsync()).FirstOrDefault();

            Assert.Equal(result.Data, model.Id);
            Assert.Equal(model.Name, Publisher.Name);
        }
コード例 #7
0
        private void Publisher_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DummyComboBoxItem  selectedPublisherItem = Publisher.SelectedItem as DummyComboBoxItem;
            PublisherViewModel foundPublisher        = publisherItems.FirstOrDefault(i => i.Id == selectedPublisherItem.Id);

            this.selectedPublisherItem = foundPublisher;
        }
コード例 #8
0
        public async Task <CommandResult> ExecuteAsync(PublisherViewModel model)
        {
            try
            {
                if (!ValidationData(model))
                {
                    return(CommandResult.Failed(new CommandResultError()
                    {
                        Code = (int)HttpStatusCode.NotAcceptable,
                        Description = "Data not correct"
                    }));
                }

                if (model.Id != 0)
                {
                    var publisher = await _publisherRepository.GetByIdAsync(model.Id);

                    if (publisher == null)
                    {
                        return(CommandResult.Failed(new CommandResultError()
                        {
                            Code = (int)HttpStatusCode.NotFound,
                            Description = "Data not found"
                        }));
                    }

                    publisher.Name    = model.Name;
                    publisher.Address = model.Address;
                    publisher.Phone   = model.Phone;
                    publisher.Email   = model.Email;
                    publisher.Enabled = model.Enabled;

                    await _publisherRepository.UpdateAsync(publisher);
                }
                else
                {
                    Publishers entity = new Publishers();
                    entity.Name    = model.Name;
                    entity.Address = model.Address;
                    entity.Phone   = model.Phone;
                    entity.Email   = model.Email;
                    entity.Enabled = model.Enabled;

                    await _publisherRepository.InsertAsync(entity);

                    model.Id = entity.Id;
                }

                return(CommandResult.SuccessWithData(model.Id));
            }
            catch (Exception ex)
            {
                return(CommandResult.Failed(new CommandResultError()
                {
                    Code = (int)HttpStatusCode.InternalServerError,
                    Description = ex.Message
                }));
            }
        }
コード例 #9
0
 private bool ValidationData(PublisherViewModel model)
 {
     if (model == null || model.Name == null)
     {
         return(false);
     }
     return(true);
 }
コード例 #10
0
 private bool ValidationData(PublisherViewModel model)
 {
     if (model == null || string.IsNullOrEmpty(model.Name))
     {
         return(false);
     }
     return(true);
 }
コード例 #11
0
        public PublisherViewModelTests()
        {
            _eventAggregator = new Mock <IEventAggregator>();

            _mockedEvent = _eventAggregator.RegisterNewMockedEvent <MessageSubmittedEvent, MessageContent>();

            _viewModel = new PublisherViewModel(_eventAggregator.Object);
        }
コード例 #12
0
        public static Publisher PublisherViewModelToPublisher(PublisherViewModel publisherVM)
        {
            Publisher publisher = new Publisher();

            publisher.Name        = publisherVM.Name;
            publisher.Description = publisherVM.Description;

            return(publisher);
        }
コード例 #13
0
        // GET: Publishers
        public async Task <IActionResult> Index(string SearchString, int productPage = 1)
        {
            PublisherViewModel publisherVM = new PublisherViewModel();

            if (string.IsNullOrEmpty(SearchString))
            {
                publisherVM = new PublisherViewModel()
                {
                    publishers = _context.Publishers.Include(p => p.ApplicationUser).Include(p => p.Country).Include(p => p.Speciality)
                };
            }
            else if (!string.IsNullOrEmpty(SearchString))
            {
                publisherVM = new PublisherViewModel()
                {
                    publishers = _context.Publishers.Where(a => a.ArName.Contains(SearchString) || a.EnName.Contains(SearchString) || a.Description.Contains(SearchString) || a.Logo.Contains(SearchString) || a.Email.Contains(SearchString) || a.ApplicationUser.ArName.Contains(SearchString) || a.Country.ArCountryName.Contains(SearchString) || a.Website.Contains(SearchString) || a.Fb.Contains(SearchString) || a.ContactUs.Contains(SearchString) || a.EnName.Contains(SearchString) || a.Languages.Contains(SearchString) || a.Tags.Contains(SearchString) || a.Address.Contains(SearchString) || a.RegistrationNumber.Contains(SearchString)).Include(p => p.ApplicationUser).Include(p => p.Country).Include(p => p.Speciality)
                };
            }
            if (SearchString == "reported")
            {
                publisherVM = new PublisherViewModel()
                {
                    publishers = _context.Publishers.Where(a => a.ReportType.ToString() != "None").Include(p => p.ApplicationUser).Include(p => p.Country).Include(p => p.Speciality)
                };
            }
            if (SearchString == "featured")
            {
                publisherVM = new PublisherViewModel()
                {
                    publishers = _context.Publishers.Where(a => a.IsFeatured == true).Include(p => p.ApplicationUser).Include(p => p.ApplicationUser).Include(p => p.Country).Include(p => p.Speciality)
                };
            }
            if (SearchString == "acceptance")
            {
                publisherVM = new PublisherViewModel()
                {
                    publishers = _context.Publishers.Where(a => a.IsAdminAccepted == false).Include(p => p.ApplicationUser).Include(p => p.ApplicationUser).Include(p => p.Country).Include(p => p.Speciality)
                };
            }

            var count = publisherVM.publishers.Count();

            publisherVM.publishers = publisherVM.publishers.OrderBy(p => p.Id)
                                     .Skip((productPage - 1) * PagSize)
                                     .Take(PagSize).ToList();


            publisherVM.PagingInfo = new PagingInfo
            {
                CurrentPage  = productPage,
                ItemsPerPage = PagSize,
                TotalItem    = count
            };

            //var aRIDDbContext = _context.Publisher.Include(p => p.ApplicationUser).Include(p => p.Country).Include(p => p.Speciality);
            return(View(publisherVM));
        }
コード例 #14
0
        /// <summary>
        /// Remove uma editora.
        /// </summary>
        /// <param name="viewModel">ViewModel com as informações da editora.</param>
        /// <returns></returns>
        public async Task <bool> DeletePublisher(PublisherViewModel viewModel)
        {
            var publisher = viewModel.AutoMapear <PublisherViewModel, Publisher>();

            _repository.Delete(publisher);
            OperationSuccesful = await _repository.Commit();

            return(OperationSuccesful);
        }
コード例 #15
0
        public ActionResult Create()
        {
            var viewModel = new PublisherViewModel();

            this.ViewData[ContextKeys.ControllerName] = ControllerName;
            this.ViewData[ContextKeys.ActionName]     = CreateActionName;
            this.ViewBag.Title = Strings.CreatePageTitle;
            return(this.View(ViewNames.Edit, viewModel));
        }
コード例 #16
0
        public void AddPublisher(PublisherViewModel publisher)
        {
            var _publisher = new Publisher()
            {
                Name = publisher.Name
            };

            _context.Publishers.Add(_publisher);
            _context.SaveChanges();
        }
コード例 #17
0
        public void CreatePublisher_ReturnsIActionResultWhenEntity()
        {
            // Arrange
            var entity = new PublisherViewModel();

            // Act
            var result = _publisherController.CreatePublisher(entity) as IActionResult;

            // Assert
            Assert.NotNull(result);
        }
コード例 #18
0
        public void Update_InvalidUpdatePublisher_ReturnViewResult()
        {
            var fakePublisherViewModel = new PublisherViewModel();

            _sut.ModelState.Add("testError", new ModelState());
            _sut.ModelState.AddModelError("testError", "test");

            var res = _sut.Update(fakePublisherViewModel);

            Assert.IsType <ViewResult>(res);
        }
コード例 #19
0
        public ActionResult AddPublisher(PublisherViewModel publisherViewModel)
        {
            if (ModelState.IsValid)
            {
                var publisher = _mapper.Map <PublisherViewModel, Publisher>(publisherViewModel);
                _publisherService.Add(publisher, CurrentLanguageCode);
                return(RedirectToAction("GetPublishers"));
            }

            return(View(publisherViewModel));
        }
コード例 #20
0
        public async Task <IActionResult> Add(PublisherViewModel viewModel)
        {
            var publisher = await _publisherService.AddPublisher(viewModel);

            if (_publisherService.IsSuccessful() == false)
            {
                AddModelError(_publisherService.GetModelErrors());
                return(View(nameof(Edit), publisher));
            }

            return(RedirectToAction(nameof(Edit), new { publisher.PublisherId }));
        }
コード例 #21
0
ファイル: PublishersService.cs プロジェクト: n-skriabin/CRUD
        public PublisherViewModel DomainToViewModel(ResponsePublisherViewModel responsePublisherViewModel, Guid publisherId)
        {
            PublisherViewModel publisherViewModel = new PublisherViewModel
            {
                Id           = responsePublisherViewModel.Id,
                Name         = responsePublisherViewModel.Name,
                BooksList    = _bookRepository.GetBooks(publisherId),
                JournalsList = _journalRepository.GetJournals(publisherId),
            };

            return(publisherViewModel);
        }
コード例 #22
0
ファイル: MainWindow.xaml.cs プロジェクト: Zhytyk/pi52_vpvkr
        private void RemovePublisherBtn_Click(object sender, RoutedEventArgs e)
        {
            InitDataSource(ref publisherItems, Mapper.PublishersToPublisherViewModels, publisherController.Get);

            PublisherViewModel publisher = dataGrid.SelectedItem as PublisherViewModel;

            if (publisher != null)
            {
                publisherController.Remove(publisher.Id);
                publisherItems.Remove(publisher);
            }
        }
コード例 #23
0
        public AddBook(IList <SectionViewModel> sectionItems, IList <PublisherViewModel> publisherItems, string name, string description, Models.Condition condition, SectionViewModel selectedSectionItem, PublisherViewModel selectedPublisherItem) : this(sectionItems, publisherItems)
        {
            Name.Text                  = name;
            Description.Text           = description;
            Condition.Text             = condition.ToString();
            this.selectedSectionItem   = selectedSectionItem;
            this.selectedPublisherItem = selectedPublisherItem;
            Section.SelectedValue      = selectedSectionItem.Id;
            Publisher.SelectedValue    = selectedPublisherItem.Id;

            addBtn.Content = Constants.EDIT;
        }
コード例 #24
0
        public IActionResult Publisher(string id)
        {
            var publisher            = publisherRepository.GetPublisherByPublisherId(id);
            PublisherViewModel model = new PublisherViewModel
            {
                PublisherId = publisher.PublisherId,
                Name        = $"{publisher.Name}",
                Region      = publisher.Region,
                Books       = publisherRepository.GetBooksByPublisherId(publisher.PublisherId),
            };

            return(View(model));
        }
コード例 #25
0
 private void InitializeTestData(out PublisherViewModel publisherViewModel)
 {
     publisherViewModel = new PublisherViewModel
     {
         CompanyName    = "name",
         CompanyNameRu  = "name ru",
         Description    = "desc",
         DescriptionRu  = "desc ru",
         HomePage       = "homePage",
         HomePageRu     = "homePage ru",
         OldCompanyName = "old name"
     };
 }
コード例 #26
0
ファイル: PublisherController.cs プロジェクト: fcdk/MVCTask
        public ActionResult Create(PublisherViewModel model)
        {
            if (ModelState.IsValid)
            {
                var publisher = _mapper.Map <Publisher>(model);
                _unitOfWork.Publishers.Insert(publisher);
                _unitOfWork.Save();

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            return(View());
        }
コード例 #27
0
        public IHttpActionResult Put(PublisherViewModel publisherViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var publisher = _mapper.Map <PublisherViewModel, Publisher>(publisherViewModel);

            _publisherService.Update(publisher, CurrentLanguage);

            return(Ok());
        }
コード例 #28
0
        public ActionResult Create(PublisherViewModel model)
        {
            if (ModelState.IsValid)
            {
                var publisher = Mapper.Map <CreateUpdatePublisherInput>(model);
                gameService.Create(publisher);
                TempData["ResultMsg"] = "The publisher was added successfully!";
                return(RedirectToAction("Details", "Publisher", new { companyName = model.CompanyName }));
            }

            TempData["ResultMsg"] = "Some fields of game is not valid!";
            return(View(model));
        }
コード例 #29
0
        public async Task <IActionResult> Edit(PublisherViewModel viewModel)
        {
            var publisher = await _publisherService.UpdatePublisher(viewModel);

            if (_publisherService.IsSuccessful() == false)
            {
                AddModelError(_publisherService.GetModelErrors());
                return(View(nameof(Edit), publisher));
            }
            else
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
コード例 #30
0
        public IActionResult GetPublisher()
        {
            var publshers = _iPublisherService.GetAll();
            List <PublisherViewModel> lPvm = new List <PublisherViewModel>();

            foreach (var item in publshers)
            {
                PublisherViewModel pvm = new PublisherViewModel();
                pvm.Id   = item.Id;
                pvm.Name = item.Name;
                lPvm.Add(pvm);
            }
            return(Ok(lPvm));
        }