Esempio n. 1
0
        private LeaveScheduleViewModel MapDTOWithViewModel(LeaveScheduleDTO lsDto)
        {
            InitializeMapper();
            LeaveScheduleViewModel ls = Mapper.Map <LeaveScheduleDTO, LeaveScheduleViewModel>(lsDto);

            return(ls);
        }
Esempio n. 2
0
        private LeaveScheduleDTO MapViewModelWithDTO(LeaveScheduleViewModel ls)
        {
            Mapper.Initialize(cfg => cfg.CreateMap <LeaveScheduleViewModel, LeaveScheduleDTO>());
            Mapper.Initialize(cfg => {
                cfg.CreateMap <LeaveScheduleViewModel, LeaveScheduleDTO>();
                cfg.CreateMap <AnnualLeaveViewModel, AnnualLeaveDTO>()
                .ForMember(al => al.Employee, opt => opt.Ignore())
                .ForMember(al => al.LeaveSchedule, opt => opt.Ignore());
            });
            LeaveScheduleDTO lsDto = Mapper.Map <LeaveScheduleViewModel, LeaveScheduleDTO>(ls);

            return(lsDto);
        }
Esempio n. 3
0
 public async Task <ActionResult> Create(LeaveScheduleViewModel ls)
 {
     try {
         LeaveScheduleDTO lsDto = MapViewModelWithDTO(ls);
         await(_leaveScheduleService as LeaveScheduleService).CreateAsync(lsDto);
         return(RedirectToAction("Index"));
     }
     catch (ValidationException ex) {
         _logger.Warn(ex.Message);
         ModelState.AddModelError(ex.Property, ex.Message);
     }
     return(View("Create", ls));
 }
Esempio n. 4
0
        private async Task <ActionResult> GetViewAsync(int?id, string viewName)
        {
            try {
                LeaveScheduleDTO lsDto = await _leaveScheduleService.FindByIdAsync(id);

                LeaveScheduleViewModel ls = MapDTOWithViewModel(lsDto);
                return(View(viewName, ls));
            }
            catch (ValidationException ex) {
                _logger.Warn(ex.Message);
                return(View("Error", new string[] { ex.Message }));
            }
        }
Esempio n. 5
0
        public async Task Delete_Get_ModelIsValid_RetrievesLeaveScheduleFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.FindByIdAsync(It.IsAny <int?>())).ReturnsAsync((int?_id) => new LeaveScheduleDTO {
                Id   = _id.Value,
                Year = 2018
            });
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Delete(7)) as ViewResult;

            LeaveScheduleViewModel model = result.ViewData.Model as LeaveScheduleViewModel;

            Assert.AreEqual(7, model.Id);
            Assert.AreEqual(2018, model.Year);
        }
Esempio n. 6
0
        public async Task Edit_Post_ModelIsInvalid_RetrievesLeaveScheduleFromModel()
        {
            Mock <LeaveScheduleService> mock = new Mock <LeaveScheduleService>();

            mock.Setup(m => m.EditAsync(It.IsAny <LeaveScheduleDTO>())).Throws(new ValidationException("", ""));
            LeaveScheduleController controller = GetNewLeaveScheduleController(mock.Object);

            ViewResult result = (await controller.Edit(new LeaveScheduleViewModel {
                Id = 7,
                Year = 2018
            })) as ViewResult;

            LeaveScheduleViewModel model = result.ViewData.Model as LeaveScheduleViewModel;

            Assert.AreEqual(7, model.Id);
            Assert.AreEqual(2018, model.Year);
        }