public void TestErrorViewOnSubscription()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new HomeMyDayDbContext(optionsBuilder.Options);

            context.Newspapers.Add(new Newspaper()
            {
                Email = "*****@*****.**"
            });

            context.SaveChanges();

            var repository            = new EFNewspaperRepository(context);
            INewspaperManager manager = new NewspaperManager(repository);
            var target             = new NewspaperController(manager);
            var newspaperViewModel = new NewspaperViewModel()
            {
                Email = "*****@*****.**"
            };
            var result = target.Index(newspaperViewModel);

            Assert.NotNull(result);
            Assert.NotNull(newspaperViewModel);
            Assert.Null(result.ViewName);
            Assert.NotNull(result.ViewData);
            Assert.True(result.ViewData.ModelState.ErrorCount > 0);
        }
示例#2
0
 public ActionResult Edit([Bind(Include = "ID,Name,Category")] NewspaperViewModel newspaperviewmodel)
 {
     if (ModelState.IsValid)
     {
         Newspaper newspaper = Mapper.Map <NewspaperViewModel, Newspaper>(newspaperviewmodel);
         _service.SaveNewspaper(newspaper);
         return(RedirectToAction("Index"));
     }
     return(View(newspaperviewmodel));
 }
示例#3
0
        public ActionResult Create([Bind(Include = "ID,Name,Category")] NewspaperViewModel newspaperviewmodel)
        {
            if (ModelState.IsValid)
            {
                _service.AddNewspaper(newspaperviewmodel.Name, newspaperviewmodel.Category);
                return(RedirectToAction("Index"));
            }

            return(View(newspaperviewmodel));
        }
示例#4
0
        public ViewResult Index(NewspaperViewModel newspaperViewModel)
        {
            if (ModelState.IsValid)
            {
                if (_newspaperManager.Subscribe(newspaperViewModel.Email))
                {
                    return(View("Result"));
                }
            }

            ModelState.AddModelError("Error", "Het ingevulde emailadres is niet correct of is al gebruikt.");
            return(View());
        }
示例#5
0
        // GET: /Newspaper/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NewspaperViewModel newspaperviewmodel = Mapper.Map <Newspaper, NewspaperViewModel>(_service.FindNewspaper(id));

            if (newspaperviewmodel == null)
            {
                return(HttpNotFound());
            }
            return(View(newspaperviewmodel));
        }
示例#6
0
        public IHttpActionResult Delete(NewspaperViewModel newspaperFromView)
        {
            var newspaperForDelete = _newspaperService.Get().FirstOrDefault(n => n.Id == newspaperFromView.Id);
            var unitForDelete      = _libraryStorageUnitService.Get().FirstOrDefault(u => u.Id == newspaperFromView.UnitId);

            if (newspaperForDelete == null || unitForDelete == null)
            {
                return(BadRequest());
            }
            _newspaperService.Delete(newspaperForDelete);
            _libraryStorageUnitService.Delete(unitForDelete);

            return(Ok(newspaperFromView));
        }
示例#7
0
        public IHttpActionResult Add(NewspaperViewModel newspaperFromView)
        {
            if (newspaperFromView == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var libraryStorageUnitForAdd = Mapper.Map <NewspaperViewModel, LibraryStorageUnitDTO>(newspaperFromView);

            var newspaperForAdd = Mapper.Map <NewspaperViewModel, NewspaperDTO>(newspaperFromView);

            newspaperForAdd.Unit = libraryStorageUnitForAdd;
            _newspaperService.Create(newspaperForAdd);

            return(Ok(newspaperFromView));
        }
        public void AddNewspaper(NewspaperViewModel nvm)
        {
            int _id = _newspaperRepository.Create(new Newspaper
            {
                Name = nvm.Name,
                Date = nvm.Date,
            }).Id;
            List <NewspaperAuthor> _newspaperAuthors = nvm.Authors.Select(c => new NewspaperAuthor {
                NewspaperId = _id, AuthorId = (int)c.Id
            }).ToList();

            _newspaperAuthorRepository.AddRange(_newspaperAuthors);
            List <NewspaperPublishingHouse> _newspaperPublishingHouses = nvm.PublishingHouses.Select(c => new NewspaperPublishingHouse {
                NewspaperId = _id, PublishingHouseId = (int)c.Id
            }).ToList();

            _newspaperPublishingHouseRepository.AddRange(_newspaperPublishingHouses);
        }
        public void UpdateNewspaper(NewspaperViewModel nvm)
        {
            _newspaperRepository.Update(new Newspaper {
                Id = (int)nvm.Id, Name = nvm.Name, Date = nvm.Date
            });
            List <NewspaperAuthor> _newspaperAuthors = nvm.Authors.Select(c => new NewspaperAuthor {
                NewspaperId = (int)nvm.Id, AuthorId = (int)c.Id
            }).ToList();

            _newspaperAuthorRepository.RemoveRange(_newspaperAuthorRepository.GetAll().Where(a => a.NewspaperId == (int)nvm.Id).ToList());
            _newspaperAuthorRepository.AddRange(_newspaperAuthors);
            List <NewspaperPublishingHouse> _newspaperPublishingHouses = nvm.PublishingHouses.Select(c => new NewspaperPublishingHouse {
                NewspaperId = (int)nvm.Id, PublishingHouseId = (int)c.Id
            }).ToList();

            _newspaperPublishingHouseRepository.RemoveRange(_newspaperPublishingHouseRepository.GetAll().Where(a => a.NewspaperId == (int)nvm.Id).ToList());
            _newspaperPublishingHouseRepository.AddRange(_newspaperPublishingHouses);
        }
        public void TestResultViewWithWhiteSpaceOnSubscription()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new HomeMyDayDbContext(optionsBuilder.Options);
            INewspaperRepository repository = new EFNewspaperRepository(context);
            INewspaperManager    manager    = new NewspaperManager(repository);
            var target             = new NewspaperController(manager);
            var newspaperViewModel = new NewspaperViewModel()
            {
                Email = "  [email protected]  "
            };
            var result = target.Index(newspaperViewModel);

            Assert.NotNull(result);
            Assert.NotNull(newspaperViewModel);
            Assert.NotNull(result.ViewName);
            Assert.Equal("Result", result.ViewName);
        }
示例#11
0
        public IHttpActionResult Edit(NewspaperViewModel newspaperFromView)
        {
            if (newspaperFromView == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var libraryStorageUnitForEdit = Mapper.Map <NewspaperViewModel, LibraryStorageUnitDTO>(newspaperFromView);
                _libraryStorageUnitService.Edit(libraryStorageUnitForEdit);

                var newspaperForEdit = Mapper.Map <NewspaperViewModel, NewspaperDTO>(newspaperFromView);
                _newspaperService.Edit(newspaperForEdit);
            }
            catch (ObjectNotFoundException)
            {
                return(BadRequest());
            }

            return(Ok(newspaperFromView));
        }