public ActionResult Delete(CompanyArea companyArea)
        {
            try
            {
                _companyAreasService.DeleteCompanyArea(companyArea.Id);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public ActionResult Create(CompanyArea companyArea)
        {
            try
            {
                if (!ModelState.IsValid)
                    return View(companyArea);

                _companyAreasService.CreateCompanyArea(companyArea);

                return RedirectToAction("Index");
            }
            catch (ObjectExistsException<CompanyArea> ex)
            {
                ModelState.AddModelError("CompanyAreaExists", ex.Message);
                return View(companyArea);
            }
            catch
            {
                return View();
            }
        }
Esempio n. 3
0
        public void Should_Map_CheckinToolTabViewModel_To_CheckinTool_When_All_Fields_Are_Populated()
        {
            //Arrange
            var employee = new Employee
            {
                Id = 1,
                Name = "Celso"
            };

            var tool = new Tool
            {
                Id = 1,
                Name = "Ferramenta 1"
            };

            var companyArea = new CompanyArea
            {
                Id = 1,
                Name = "Portões"
            };

            var createCheckinToolTabViewModel = CheckinToolDummies.CreateOneCheckinToolTabViewModel(tool.Id);

            var holderServiceMock = new Mock<IHolderService>();
            var toolServiceMock = new Mock<IToolService>();
            var checkinToolServiceMock = new Mock<ICheckinToolService>();
            var companyAreaServiceMock = new Mock<ICompanyAreasService>();

            holderServiceMock.Setup(x => x.FindHolderByName(createCheckinToolTabViewModel.HolderName))
                .Returns(employee);
            toolServiceMock.Setup(x => x.FindTool(createCheckinToolTabViewModel.ToolId))
                .Returns(tool);
            companyAreaServiceMock.Setup(x => x.FindCompanyAreaByName(createCheckinToolTabViewModel.CompanyAreaName))
                .Returns(companyArea);

            var toolMapper = new ToolMapper(null, null, toolServiceMock.Object, holderServiceMock.Object, companyAreaServiceMock.Object, checkinToolServiceMock.Object);

            //Act
            var checkinTool = toolMapper.MapCheckinToolTabViewModelToCheckinTool(createCheckinToolTabViewModel);

            //Assert
            checkinToolServiceMock.VerifyAll();
            toolServiceMock.VerifyAll();
            holderServiceMock.VerifyAll();
            Assert.IsNotNull(checkinTool.EmployeeCompanyHolderId);
            Assert.IsNotNull(checkinTool.Tool);
            Assert.IsNotNull(checkinTool.CheckinDateTime);
            Assert.IsNotNull(checkinTool.CompanyAreaId);
        }