Exemplo n.º 1
0
        public ActionResult Index(CreateAJobViewModel model)
        {
            if (ModelState.IsValid)
            {
                //try
                //{
                var job     = this.jobService.MapJob(model);
                var company = User.Identity.GetUserId();
                this.jobService.AddJobToCompany(company, job);
                this.TempData["Success"] = "Successfully created job " + job.Title;
                return(RedirectToAction("Index", "Home"));
                //}
                //catch (DbEntityValidationException e)
                //{
                //    foreach (var eve in e.EntityValidationErrors)
                //    {
                //       var asd = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                //            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                //        foreach (var ve in eve.ValidationErrors)
                //        {
                //            var qwe = string.Format("- Property: \"{0}\", Error: \"{1}\"",
                //                ve.PropertyName, ve.ErrorMessage);
                //        }
                //    }
                //}
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
 public Job MapJob(CreateAJobViewModel model)
 {
     this.job.Title       = model.Title;
     this.job.Description = model.Description;
     this.job.Tags        = model.GetTags();
     return(this.job);
 }
Exemplo n.º 3
0
        public CreateAJobController(ICreateAJobService jobService, CreateAJobViewModel jobViewModel)
        {
            if (jobService == null)
            {
                throw new ArgumentException("job");
            }

            if (jobViewModel == null)
            {
                throw new ArgumentException("viewmodel");
            }

            this.jobService   = jobService;
            this.jobViewModel = jobViewModel;
        }
        public void MapJobProperly()
        {
            //Arrange
            var company             = new Company();
            var tags                = new List <Tag>();
            var createAJobViewModel = new CreateAJobViewModel()
            {
                Description = "Description",
                Title       = "Title"
            };

            var mockedCompanyRepository = new Mock <IEfRepository <Company> >();
            var mockedJobRepository     = new Mock <IEfRepository <Job> >();
            var mockedJob        = new Mock <Job>();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var service          = new CreateAJobService(mockedCompanyRepository.Object, mockedJobRepository.Object, mockedJob.Object, mockedUnitOfWork.Object);

            //Act
            var mapped = service.MapJob(createAJobViewModel);

            //Assert
            Assert.AreEqual(createAJobViewModel.Title, "Title");
            Assert.AreEqual(createAJobViewModel.Description, "Description");
        }