Ejemplo n.º 1
0
 public ActionResult Edit(Employer mEmployer)
 {
     if (ModelState.IsValid)
     {
         var emp = _employerService.GetEmployerById(mEmployer.EmployerId);
         if (TryUpdateModel(emp))
         {
             if (ExecuteRepositoryAction(() => { _employerService.UpdateEmployer(emp); _employerService.CommitChanges(); }))
             {
                 return(ReturnJsonFormSuccess());
             }
         }
     }
     return(PartialView(mEmployer));
 }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> UpdateEmployer(EmployerViewModel employerVM)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(new { Error = "ModelState Invalid!" }));
            }
            try
            {
                var employer = await employerService.UpdateEmployer(employerVM);

                return(Ok(new { Success = employer }));
            }
            catch (Exception ex)
            {
                return(Ok(new { Error = ex.Message }));
            }
        }
Ejemplo n.º 3
0
        public void UpdatedEmployerShoundBeLikeEmployerToUpdate()
        {
            //Arrange
            NewEmployerVm employer = new NewEmployerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit"
            };

            NewEmployerVm employerToUpdate = new NewEmployerVm()
            {
                Id   = 1,
                Name = "test2",
                NIP  = "Unit2"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var employerService = new EmployerService(mapper, new EmployerRepository(context));
                employerService.AddEmployer(employer);
            }

            using (var context = new Context(options))
            {
                var employerService = new EmployerService(mapper, new EmployerRepository(context));
                employerService.UpdateEmployer(employerToUpdate);

                //Assert
                context.Employers.FirstOrDefaultAsync(e => e.Id == 1).Should().Equals(employerToUpdate);
            }
        }