Пример #1
0
        protected override async Task <bool> DoVerifyEntity(Order entity)
        {
            if (entity.Time == null)
            {
                throw new ArgumentNullException(nameof(entity.Time));
            }

            if (!await CustomerService.IsExist(entity.CustomerId))
            {
                throw new EntityNotFoundException($"CustomerId:{entity.CustomerId} not found", "Customer");
            }

            if (!await CargoService.IsExist(entity.CargoId))
            {
                throw new EntityNotFoundException($"GargoId:{entity.CargoId} not found", "Cargo");
            }

            if (!await RouteService.IsExist(entity.RouteId))
            {
                throw new EntityNotFoundException($"RouteId:{entity.RouteId} not found", "Route");
            }

            if (!await BillService.IsExist(entity.BillId))
            {
                throw new EntityNotFoundException($"BillId:{entity.BillId}", "Bill");
            }

            return(true);
        }
Пример #2
0
        public ActionResult Edit(int id, Cargo cargo)
        {
            if (id != cargo.CargoID || cargo == null)
            {
                return(NotFound());
            }

            try
            {
                if (ModelState.IsValid)
                {
                    CargoService service = new CargoService();
                    service.ValidarCampos(cargo);

                    _cargo.Atualizar(cargo);
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(cargo));
            }
            catch (Exception ex)
            {
                Mensagem = ex.Message.ToString();
                ModelState.AddModelError(String.Empty, Mensagem);
                return(View(cargo));
            }
        }
        public CargoServiceTestSuite()
        {
            CargoRepositoryMock = new Mock <ICargoRepository>();

            CargoService = new CargoService(
                CargoRepositoryMock.Object);
        }
Пример #4
0
        public static MvcHtmlString SelectCargo(this HtmlHelper html, int idCargo = 0)
        {
            var cargos = new CargoService().Listar()
                         .Where(x => x.Ativo == true)
                         .OrderBy(x => x.Descricao)
                         .ToList();

            TagBuilder tag = new TagBuilder("select");

            tag.MergeAttribute("id", "CargoId");
            tag.MergeAttribute("name", "CargoId");
            tag.MergeAttribute("class", "form-control");

            foreach (var item in cargos)
            {
                TagBuilder itemTag = new TagBuilder("option");
                itemTag.MergeAttribute("value", item.CargoId.ToString());
                if (item.CargoId == idCargo)
                {
                    itemTag.MergeAttribute("selected", "selected");
                }
                itemTag.SetInnerText(item.Descricao);
                tag.InnerHtml += itemTag.ToString();
            }

            return(new MvcHtmlString(tag.ToString()));
        }
Пример #5
0
        private async Task <RuleResult> RegistrationNumberValidator()
        {
            try
            {
                var isEmpty = string.IsNullOrEmpty(RegistrationNumber.Value);
                if (isEmpty)
                {
                    return(RuleResult.Invalid($"Укажите регистрационный номер. Пример: Х000ХХ777"));
                }

                var isValid = await CargoService.ValidateRegistrationNumber(RegistrationNumber.Value, RequestPriority.UserInitiated);

                if (!isValid)
                {
                    return(RuleResult.Invalid($"Регистрационный номер {RegistrationNumber.Value} не корректен. Пример: Х000ХХ777"));
                }

                return(RuleResult.Valid());
            }
            catch (Exception)
            {
                //TODO залогировать причину возникновения ошибки
                return(RuleResult.Invalid("Ошибка валидации регистрационного номера"));
            }
        }
Пример #6
0
        public AuditController()
        {
            _cargoLogService = new CargoLogService();
            CargoService cargoService = new CargoService();

            _cargoService = cargoService;
        }
Пример #7
0
        public ActionResult Create(Cargo cargo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!String.IsNullOrEmpty(cargo.DescricaoSumaria))
                    {
                        if (VerificarCargo(cargo.DescricaoSumaria))
                        {
                            throw new ArgumentException("Cargo já cadastrado");
                        }
                    }

                    cargo.EmpresaID = Convert.ToInt32(User.FindFirst(ClaimTypes.GroupSid).Value);

                    CargoService service = new CargoService();
                    service.PreencherCampos(cargo);

                    _cargo.Inserir(cargo);
                    return(RedirectToAction(nameof(Index)));
                }
                return(View(cargo));
            }
            catch (Exception ex)
            {
                Mensagem = ex.Message.ToString();
                ModelState.AddModelError(String.Empty, Mensagem);
                return(View(cargo));
            }
        }
Пример #8
0
 public CargoServiceTest() : base()
 {
     svc = new CargoService(dbContext);
     testObjectCreate = new Cargo {
         Id = 1, Nome = "Jovem Aprendiz", Ativo = true, DataCriacao = DateTime.Now, DataUltimaAlteracao = null
     };
     testObjectList = new Cargo();
 }
Пример #9
0
        public CargoController()
        {
            var cargoService = new CargoService();

            _cargoService    = cargoService;
            _huom2Service    = new Huom2Service();
            _cargoLogService = new CargoLogService();
        }
Пример #10
0
        public ShipmentController()
        {
            CargoService cargoService = new CargoService();

            _cargoService    = cargoService;
            _shipmentService = new ShipmentService();
            _huotService     = new HuotService();
            _huom2Service    = new Huom2Service();
        }
Пример #11
0
        private void GetCargoList()
        {
            ICargoService  cargoService  = new CargoService(employee.Username, employee.Password);
            ISensorService sensorService = new SensorService(employee.Username, employee.Password);
            List <Cargo>   cargos        = cargoService.All();
            List <Sensor>  sensors       = sensorService.All();
            Sensor         sensor        = sensors.Single(s => s.Sensor_name == SelectedDevice.ID.ToString());

            CargoList = new ObservableCollection <Cargo>(cargos.Where(c => c.Sensor_id == sensor.Sensor_id));
        }
Пример #12
0
        public void DeveRetornarVazioQuandoNaoEncontraCargo()
        {
            _cargoRepositoryMock = new Mock <ICargoRepository>();
            _cargoRepositoryMock.Setup(mock => mock.ObterPorId(It.IsAny <int>())).Returns((Cargo)null);
            ICargoService cargoService = new CargoService(_cargoRepositoryMock.Object);

            var cargoRecebido = cargoService.ObterPorId(1);

            _cargoRepositoryMock.Verify(mock => mock.ObterPorId(It.IsAny <int>()), Times.Once());
            Assert.Null(cargoRecebido);
        }
Пример #13
0
        public void DeveInativarCargo()
        {
            Cargo cargo = new Cargo("Tester");

            _cargoRepositoryMock = new Mock <ICargoRepository>();
            _cargoRepositoryMock.Setup(mock => mock.Inativar(It.IsAny <int>()));
            ICargoService cargoService = new CargoService(_cargoRepositoryMock.Object);

            var mensagens = cargoService.Inativar(cargo.Id);

            _cargoRepositoryMock.Verify(mock => mock.Inativar(It.IsAny <int>()), Times.Once());
            Assert.Equal(0, mensagens.Count);
        }
Пример #14
0
        public void DeveAdicionarNovoCargo()
        {
            Cargo cargo = new Cargo("Tester");

            _cargoRepositoryMock = new Mock <ICargoRepository>();
            _cargoRepositoryMock.Setup(mock => mock.Adicionar(It.IsAny <Cargo>()));
            ICargoService cargoService = new CargoService(_cargoRepositoryMock.Object);

            var mensagens = cargoService.Adicionar(cargo.Mapear());

            _cargoRepositoryMock.Verify(mock => mock.Adicionar(It.IsAny <Cargo>()), Times.Once());
            Assert.Equal(0, mensagens.Count);
        }
Пример #15
0
        public void NaoDeveAtualizarQuandoCargoNaoExistir()
        {
            Cargo cargo = new Cargo("Tester");

            _cargoRepositoryMock = new Mock <ICargoRepository>();
            _cargoRepositoryMock.Setup(mock => mock.Atualizar(It.IsAny <Cargo>())).Throws <Exception>();
            ICargoService cargoService = new CargoService(_cargoRepositoryMock.Object);

            var mensagens = cargoService.Atualizar(cargo.Mapear(), cargo.Id);

            _cargoRepositoryMock.Verify(mock => mock.Atualizar(It.IsAny <Cargo>()), Times.Once());
            Assert.Equal(1, mensagens.Count);
        }
Пример #16
0
        public void DeveObterCargoPorId()
        {
            Cargo cargo = new Cargo("Tester");

            _cargoRepositoryMock = new Mock <ICargoRepository>();
            _cargoRepositoryMock.Setup(mock => mock.ObterPorId(It.IsAny <int>())).Returns(cargo);
            ICargoService cargoService = new CargoService(_cargoRepositoryMock.Object);

            var cargoRecebido = cargoService.ObterPorId(cargo.Id);

            _cargoRepositoryMock.Verify(mock => mock.ObterPorId(It.IsAny <int>()), Times.Once());
            Assert.Equal(cargo, cargoRecebido);
        }
Пример #17
0
        public void NaoDeveAtualizarCargoInvalido()
        {
            Cargo cargo = new Cargo("");

            _cargoRepositoryMock = new Mock <ICargoRepository>();
            _cargoRepositoryMock.Setup(mock => mock.Atualizar(It.IsAny <Cargo>()));
            ICargoService cargoService = new CargoService(_cargoRepositoryMock.Object);

            var mensagens = cargoService.Atualizar(cargo.Mapear(), cargo.Id);

            _cargoRepositoryMock.Verify(mock => mock.Atualizar(It.IsAny <Cargo>()), Times.Never());
            Assert.Equal(1, mensagens.Count);
            Assert.Equal("Cargo invalido", mensagens[0]);
        }
        public void Setup()
        {
            // Setup unit of work with fake data to all including repos that using in unit of work
            Mock <ICargoTypeCategoryRepository> cargoTypeCategoryRepo = new Mock <ICargoTypeCategoryRepository>();
            Mock <ICargoTypeRepository>         cargoTypeRepo         = new Mock <ICargoTypeRepository>();

            cargoTypeCategoryRepo.Setup(repo => repo.GetAll()).Returns(CargoTypeCategoryFakeItems);
            cargoTypeRepo.Setup(rep => rep.GetAll()).Returns(CargoTypesFakeItems);
            _mockUnitOfWork = new Mock <IUnitOfWork>();
            _mockUnitOfWork.Setup(r => r.CargoTypeCategories).Returns(cargoTypeCategoryRepo.Object);
            _mockUnitOfWork.Setup(r => r.CargoTypes).Returns(cargoTypeRepo.Object);
            _cargoService = new CargoService(_mockUnitOfWork.Object);
            // Load mapping
            AutomapperConfiguration.Load();
        }
Пример #19
0
        public void DeveRetornarTodosCargos()
        {
            IList <Cargo> listaCargos = new List <Cargo>();

            listaCargos.Add(new Cargo("Tester"));
            listaCargos.Add(new Cargo("Dev"));

            _cargoRepositoryMock = new Mock <ICargoRepository>();
            _cargoRepositoryMock.Setup(mock => mock.ObterTodos()).Returns(listaCargos);
            ICargoService cargoService = new CargoService(_cargoRepositoryMock.Object);

            var cargoRecebido = cargoService.ObterTodos();

            _cargoRepositoryMock.Verify(mock => mock.ObterTodos(), Times.Once());
            Assert.NotNull(cargoRecebido);
            Assert.Equal(2, cargoRecebido.Count);
        }
Пример #20
0
        private async Task InitAvailableCargoParams()
        {
            AvailableCatalogItems = await CargoService.GetAvailableParams(RequestPriority.UserInitiated);

            var brands = AvailableCatalogItems.Brands.Select(i => i.Name);

            Brands.Value = brands.ToList();
            Brand.Value  = brands.FirstOrDefault();

            var kinds = AvailableCatalogItems.Kinds.Select(i => i.Name);

            Kinds.Value = kinds.ToList();
            Kind.Value  = kinds.FirstOrDefault();

            var weights = AvailableCatalogItems.Weights.Select(i => i.Name);

            Weights.Value = weights.ToList();
            Weight.Value  = weights.FirstOrDefault();
        }
Пример #21
0
        public async Task <Order> CreateOrder(BookingAM booking)
        {
            using (var transaction = await TransactionService.BeginTransaction())
            {
                try
                {
                    var domainCustomer = await CustomerService.GetDomainCustomer(booking.Customer);

                    var domainCargo = await CargoService.CreateDomainCargo(booking.Cargo);

                    var domainBill = await BillService.CreateDomainBill(booking.BillInfo, booking.Basket);

                    var route = await RouteService.GetRoute(booking.RootAddress, booking.Waypoints);

                    var domainRoute = await RouteService.CreateDomainRoute(route);

                    var result = await DomainOrderService.Create(
                        booking.OrderTime,
                        domainCustomer.Id,
                        domainCargo.Id,
                        domainRoute.Id,
                        domainBill.Id);

                    await OrderStateService.New(result.Id);

                    transaction.Commit();

                    return(result);
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
Пример #22
0
 public CargoController(CargoService cargoService)
 {
     _cargoService = cargoService;
 }
Пример #23
0
 public UsuarioController(UsuarioService usuarioService, CargoService cargoService)
 {
     _usuarioService = usuarioService;
     _cargoService   = cargoService;
 }
Пример #24
0
        public HuotController()
        {
            CargoService cargoService = new CargoService();

            _cargoService = cargoService;
        }
Пример #25
0
        public IActionResult Index(string filtro = "")
        {
            var service = new CargoService();

            return(View(service.Listar(filtro)));
        }
 public CargoesController(TrnspMngmntContext context, UserManager <Company> userManager)
 {
     _context      = context;
     _userManager  = userManager;
     _cargoService = new CargoService(context, userManager);
 }
 public GuardianController(CargoService cargoService)
 {
     this.cargoService = cargoService;
 }