public virtual ActionResult Create(TerminalModel terminal)
        {
            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    TerminalRepository insertionRepository = new TerminalRepository(unitOfWork.DataContext);
                    DBTerminal         dbTerminal          = new DBTerminal
                    {
                        Id                   = terminal.Id,
                        PhoneNumber          = terminal.PhoneNumber,
                        IsPublic             = terminal.IsPublic,
                        RegionId             = terminal.RegionId,
                        CorrectionFacilityId = terminal.CorrectionFacilityId,
                        Description          = terminal.Description,
                        IsActive             = terminal.IsActive
                    };
                    insertionRepository.InsertObject(dbTerminal);
                    unitOfWork.Commit();

                    // обновляем идентификатор
                    terminal.Id = dbTerminal.Id;
                }

                // сохраняем идентификатор видеотерминала
                this.WriteInformation("Видеотерминал с идентификатором \"{0}\" добавлен.", terminal.Id);

                return(RedirectToAction("Create"));
            }
            catch
            {
                return(View());
            }
        }
        public virtual ActionResult Create(TerminalModel terminal)
        {
            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    TerminalRepository insertionRepository = new TerminalRepository(unitOfWork.DataContext);
                    DBTerminal dbTerminal = new DBTerminal
                                                {
                                                    Id = terminal.Id,
                                                    PhoneNumber = terminal.PhoneNumber,
                                                    IsPublic = terminal.IsPublic,
                                                    RegionId = terminal.RegionId,
                                                    CorrectionFacilityId = terminal.CorrectionFacilityId,
                                                    Description = terminal.Description,
                                                    IsActive = terminal.IsActive
                                                };
                    insertionRepository.InsertObject(dbTerminal);
                    unitOfWork.Commit();

                    // обновляем идентификатор
                    terminal.Id = dbTerminal.Id;
                }

                // сохраняем идентификатор видеотерминала
                this.WriteInformation("Видеотерминал с идентификатором \"{0}\" добавлен.", terminal.Id);

                return RedirectToAction("Create");
            }
            catch
            {
                return View();
            }
        }
 public UnitOfWork(SignageContext context, IEventBus eventBus, IHubContext <SignageHub> signageHub)
 {
     _context         = context;
     _eventBus        = eventBus;
     _hub             = signageHub;
     Terminals        = new TerminalRepository(context);
     Signages         = new SignageRepository(context);
     TerminalSignages = new TerminalSignageRepository(context);
 }
Exemple #4
0
 public UnitOfWork(MonitoringContext context, IEventBus eventBus, IHubContext <MonitoringHub> monitoringHub)
 {
     _hub            = monitoringHub;
     _context        = context;
     _eventBus       = eventBus;
     Terminals       = new TerminalRepository(context);
     BreakLogEntries = new BreakLogEntryRepository(context);
     EmpireQueues    = new EmpireQueueRepository(context);
 }
 public void Add(ITerminal terminal)
 {
     using (IBillingRepository <ITerminal> repository = new TerminalRepository())
     {
         var entity = Mapper.Mapper.DTOtoEntity(terminal);
         repository.Add(entity);
         repository.SaveChanges();
     }
 }
Exemple #6
0
 public UnitOfWork(TerminalContext context, IEventBus eventBus, IHubContext <TerminalHub> terminalHub)
 {
     _context           = context;
     _eventBus          = eventBus;
     _hub               = terminalHub;
     Terminals          = new TerminalRepository(context);
     BreakLogEntries    = new BreakLogEntryRepository(context);
     TicketCategories   = new TicketCategoryRepository(context);
     TerminalCategories = new TerminalCategoryRepository(context);
 }
 public UnitOfWork()
 {
     _connection = new SqlConnection(ClasesBases.Properties.Settings.Default.conexion);
     Usuarios    = new UsuarioRepository(_connection);
     Autobus     = new AutoBusRepository(_connection);
     Clientes    = new ClienteRepository(_connection);
     Ciudades    = new CiudadRepository(_connection);
     Terminales  = new TerminalRepository(_connection);
     Pasajes     = new PasajeRepository(_connection);
     Servicios   = new ServicioRepository(_connection);
     Empresas    = new EmpresaRepository(_connection);
 }
        public static async Task <IActionResult> CreateCart(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/carts")] HttpRequest req,
            [CosmosDB(
                 databaseName: "smartretailboxmanagement",
                 collectionName: "Terminals",
                 ConnectionStringSetting = "CosmosDbConnectionString")] DocumentClient client,
            ILogger log)
        {
            var parameter = await HttpRequestUtility.GetRequestParameterAsync <CreateCartParameter>(req);

            var userRepo = new UserRepository(StaticHttpClient.Instance);
            var user     = await userRepo.AuthenticateUserAsync();

            if (!user.result.IsSuccess)
            {
                return(new UnauthorizedResult());
            }

            var terminalRepo = new TerminalRepository(client);
            var terminal     = await terminalRepo.FindByBoxIdAsync(parameter.BoxId);

            if (!terminal.result.IsSuccess)
            {
                return(ActionResultFactory.CreateError <CreateCartResponse>(terminal.result));
            }

            var cartRepo = new CartRepository(new CartServiceApi(StaticHttpClient.Instance));
            var cart     = await cartRepo.CreateCartAsync(terminal.info.CompanyCode, terminal.info.StoreCode, terminal.info.TerminalNo, user.info.UserId, user.info.UserName);

            if (!cart.result.IsSuccess)
            {
                return(ActionResultFactory.CreateError <CreateCartResponse>(cart.result));
            }

            var boxRepo   = new BoxRepository(client);
            var updResult = await boxRepo.SetCartIdAsync(parameter.BoxId, parameter.DeviceId, user.info.UserId, cart.info.CartId);

            if (!updResult.IsSuccess)
            {
                return(ActionResultFactory.CreateError <CreateCartResponse>(updResult));
            }

            await BoxUtility.RequestUnLockAsync(terminal.info.BoxId, terminal.info.BoxDeviceId);

            return(new CreatedResult(
                       string.Empty,
                       new CreateCartResponse
            {
                CartId = cart.info.CartId
            }));
        }
Exemple #9
0
        public UnitOfWork(SettingsContext context, IEventBus eventBus)
        {
            _context         = context;
            _eventBus        = eventBus;
            TicketCategories = new TicketCategoryRepository(context);
            Terminals        = new TerminalRepository(context);
            Signages         = new SignageRepository(context);

            //var signageSyncCommand = new SyncSignagesCommand(Signages.GetAll());
            //SourceEvent(signageSyncCommand);

            //var terminalsSyncCommand = new SyncTerminalsCommand(Terminals.GetAll());
            //SourceEvent(terminalsSyncCommand);
        }
        public IEnumerable <ITerminal> GetTerminals(Expression <Func <ITerminal, bool> > expression)
        {
            //ParameterExpression sourceParameter = expression.Parameters.FirstOrDefault(x => x.Type == typeof(ITerminal));
            //var newExpression = Billing.BL.ExpressionTransformationSupport
            //    .ParameterTypeTransformer<ITerminal, Model.Terminal>
            //    .TransformPredicate(expression, sourceParameter);
            if (expression == null)
            {
                throw new ArgumentNullException("expression", "");
            }
            IEnumerable <ITerminal> result = null;

            using (var repository = new TerminalRepository())
            {
                result = repository.GetEntities(expression)
                         .ToArray()
                         .Select(x => Mapper.Mapper.EntityToDTO(x))
                         .ToArray();
            }
            return(result);
        }
        public virtual ActionResult Delete(int id)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                TerminalRepository repository = new TerminalRepository(unitOfWork.DataContext);
                DBTerminal         dbTerminal = repository.GetObjectById(id);

                if (dbTerminal == null)
                {
                    this.WriteErrorMessage("Видеотерминал с идентификатором {0} не найден.", id);
                }
                else
                {
                    repository.DeleteObject(dbTerminal);
                    // сохраняем идентификатор удаленного видеотерминала
                    this.WriteInformation("Видеотерминал с идентификатором \"{0}\" удален.", dbTerminal.Id);
                    unitOfWork.Commit();
                }
            }
            return(RedirectToAction("List"));
        }
        public static IEnumerable<SelectListItem> GetTerminalsByCorrectionFacility(int facilityId, bool? onlyWithPublicTerminals)
        {
            using (TerminalRepository repository = new TerminalRepository())
            {
                var terminals =
                    repository.GetAllObjects()
                        .Where(t => t.CorrectionFacilityId == facilityId && t.IsDeleted == false && t.IsActive == true);

                if (onlyWithPublicTerminals != null)
                {
                    bool onlyPublic = (bool)onlyWithPublicTerminals;
                    terminals = terminals.Where(t => t.IsPublic == onlyPublic);
                }

                var returnList = terminals.OrderBy(t => t.PhoneNumber)
                        .AsEnumerable()
                        .Select(t => new SelectListItem { Value = t.Id.ToString(), Text = t.PhoneNumber })
                        .ToList();

                return returnList;
            }
        }
        public virtual ActionResult Edit(TerminalModel terminal)
        {
            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    TerminalRepository updateRepository = new TerminalRepository(unitOfWork.DataContext);
                    DBTerminal         dbTerminal       = updateRepository.GetObjectById(terminal.Id);

                    if (dbTerminal == null)
                    {
                        this.WriteErrorMessage("Видеотерминал с идентификатором {0} не найден.", terminal.Id);
                    }
                    else
                    {
                        dbTerminal.PhoneNumber          = terminal.PhoneNumber;
                        dbTerminal.IsPublic             = terminal.IsPublic;
                        dbTerminal.RegionId             = terminal.RegionId;
                        dbTerminal.CorrectionFacilityId = terminal.CorrectionFacilityId;
                        dbTerminal.Description          = terminal.Description;
                        dbTerminal.IsActive             = terminal.IsActive;

                        updateRepository.UpdateObject(dbTerminal);
                        unitOfWork.Commit();

                        // сохраняем номер телефона
                        this.WriteInformation("Видеотерминал с идентификатором \"{0}\" сохранен.", terminal.Id);
                    }
                }

                return(RedirectToAction("Details", new { id = terminal.Id }));
            }
            catch
            {
                return(View());
            }
        }
        public static IEnumerable <SelectListItem> GetTerminalsByCorrectionFacility(int facilityId, bool?onlyWithPublicTerminals)
        {
            using (TerminalRepository repository = new TerminalRepository())
            {
                var terminals =
                    repository.GetAllObjects()
                    .Where(t => t.CorrectionFacilityId == facilityId && t.IsDeleted == false && t.IsActive == true);

                if (onlyWithPublicTerminals != null)
                {
                    bool onlyPublic = (bool)onlyWithPublicTerminals;
                    terminals = terminals.Where(t => t.IsPublic == onlyPublic);
                }

                var returnList = terminals.OrderBy(t => t.PhoneNumber)
                                 .AsEnumerable()
                                 .Select(t => new SelectListItem {
                    Value = t.Id.ToString(), Text = t.PhoneNumber
                })
                                 .ToList();

                return(returnList);
            }
        }
        public IEnumerable <AddressBO> GetAddressesByType(int addressType)
        {
            DeliveryOrderDL dl = new DeliveryOrderDL();

            var list = EnumExtensions.GetEnumValues <AddressType>();
            List <AddressBO> returnList = new List <AddressBO>();

            var         specifiedType = list.FirstOrDefault(a => a.Value == addressType);
            AddressType addType;

            Enum.TryParse(specifiedType.Name, out addType);

            switch (addType)
            {
            case AddressType.Customer:
            {
                var CustomerRepository = new CustomerRepository();
                var allcustomers       = CustomerRepository.GetAll();

                foreach (var customer in allcustomers)
                {
                    var addressBO = dl.GetAddress(customer.addrkey);
                    addressBO.AddrKey = customer.addrkey;
                    addressBO.Name    = customer.custname;
                    returnList.Add(addressBO);
                }
            }
            break;

            case AddressType.Company:
            {
                var DL        = new CompanyDL();
                var companies = DL.GetCompanies();

                foreach (var company in companies)
                {
                    var addressBO = DL.GetAddress(company.addrkey);
                    addressBO.AddrKey = company.addrkey;
                    addressBO.Name    = company.compname;
                    returnList.Add(addressBO);
                }
            }
            break;

            case AddressType.ShippingPort:
            {
                var shippingRepo = new ShippingPortRepository();
                var allPorts     = shippingRepo.GetAll();
                foreach (var port in allPorts)
                {
                    var addressBO = dl.GetAddress(port.addrkey);
                    addressBO.AddrKey = port.addrkey;
                    addressBO.Name    = port.shippingportid;
                    returnList.Add(addressBO);
                }
            }
            break;

            case AddressType.Terminal:
            {
                var shippingRepo = new TerminalRepository();
                var allPorts     = shippingRepo.GetAll();
                foreach (var port in allPorts)
                {
                    var addressBO = dl.GetAddress(port.addrkey);
                    addressBO.AddrKey = port.portkey;
                    returnList.Add(addressBO);
                }
            }
            break;

            case AddressType.Warehouse:
            {
                var shippingRepo = new WarehouseRepository();
                var allPorts     = shippingRepo.GetAll();
                foreach (var port in allPorts)
                {
                    var addressBO = dl.GetAddress(port.addrkey);
                    addressBO.AddrKey = port.warehousekey;
                    addressBO.Name    = port.warehouseid;
                    returnList.Add(addressBO);
                }
            }
            break;

            case AddressType.Vendor:
            {
                var repo     = new VendorRepository();
                var allPorts = repo.GetAll();
                foreach (var port in allPorts)
                {
                    var addressBO = dl.GetAddress(port.addrkey);
                    addressBO.AddrKey = port.vendkey;
                    addressBO.Name    = port.vendname;
                    returnList.Add(addressBO);
                }
            }
            break;
            }
            return(returnList);
        }
        public virtual ActionResult Edit(TerminalModel terminal)
        {
            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    TerminalRepository updateRepository = new TerminalRepository(unitOfWork.DataContext);
                    DBTerminal dbTerminal = updateRepository.GetObjectById(terminal.Id);

                    if (dbTerminal == null)
                    {
                        this.WriteErrorMessage("Видеотерминал с идентификатором {0} не найден.", terminal.Id);
                    }
                    else
                    {
                        dbTerminal.PhoneNumber = terminal.PhoneNumber;
                        dbTerminal.IsPublic = terminal.IsPublic;
                        dbTerminal.RegionId = terminal.RegionId;
                        dbTerminal.CorrectionFacilityId = terminal.CorrectionFacilityId;
                        dbTerminal.Description = terminal.Description;
                        dbTerminal.IsActive = terminal.IsActive;

                        updateRepository.UpdateObject(dbTerminal);
                        unitOfWork.Commit();

                        // сохраняем номер телефона
                        this.WriteInformation("Видеотерминал с идентификатором \"{0}\" сохранен.", terminal.Id);
                    }

                }

                return RedirectToAction("Details", new { id = terminal.Id });
            }
            catch
            {
                return View();
            }
        }
        public virtual ActionResult Delete(int id)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                TerminalRepository repository = new TerminalRepository(unitOfWork.DataContext);
                DBTerminal dbTerminal = repository.GetObjectById(id);

                if (dbTerminal == null)
                {
                    this.WriteErrorMessage("Видеотерминал с идентификатором {0} не найден.", id);
                }
                else
                {
                    repository.DeleteObject(dbTerminal);
                    // сохраняем идентификатор удаленного видеотерминала
                    this.WriteInformation("Видеотерминал с идентификатором \"{0}\" удален.", dbTerminal.Id);
                    unitOfWork.Commit();
                }

            }
            return RedirectToAction("List");
        }
        /// <summary>
        /// 取引終了時の在庫更新を行います。
        /// </summary>
        /// <param name="parameters">パラメーター。</param>
        /// <param name="client">Cosmos DB クライアント。</param>
        /// <param name="log">ロガー。</param>
        /// <returns>非同期の操作を表すタスク。TResult パラメーターの値には、処理の結果が含まれます。</returns>
        /// <remarks>BOX で付与されたタイムスタンプ順に処理されます。</remarks>
        private static async Task <(BoxResponse, RepositoryResult)> UpdateClosingStocksAsync(
            IList <UpdateStocksParameter> parameters,
            DocumentClient client,
            ILogger log)
        {
            var terminalRepo = new TerminalRepository(client);
            var boxRepo      = new BoxRepository(client);
            var skuRepo      = new SkuRepository(client);
            var stockRepo    = new StockRepository(client);
            var cartRepo     = new CartRepository(new CartServiceApi(StaticHttpClient.Instance));

            parameters = parameters
                         .OrderBy(arg => arg.Timestamp)
                         .ToArray();

            foreach (var parameter in parameters)
            {
                // 在庫を設定します。
                var setStocksResult = await stockRepo.SetStocksAsync(
                    parameter.BoxId,
                    "1",
                    parameter.Items.Select(arg => (arg.SkuCode, arg.Quantity)).ToArray());

                if (!setStocksResult.IsSuccess)
                {
                    return(BoxResponseFactory.CreateError <BoxResponse>(setStocksResult), setStocksResult);
                }

                // ターミナルを取得します。
                (var terminalResult, var terminal) = await terminalRepo.FindByBoxIdAsync(parameter.BoxId);

                if (!terminalResult.IsSuccess)
                {
                    return(BoxResponseFactory.CreateError <BoxResponse>(terminalResult), terminalResult);
                }

                // BOX を取得します。
                (var boxResult, var box) = await boxRepo.FindByBoxIdAsync(parameter.BoxId);

                if (!boxResult.IsSuccess)
                {
                    return(BoxResponseFactory.CreateError <BoxResponse>(boxResult), boxResult);
                }

                // 取引開始時と比較して、在庫数に差異がある BOX 商品を取得します。
                (var stockDifferencesResult, var stockReferrences) = await stockRepo.GetStockDifferencesAsync(parameter.BoxId);

                if (!stockDifferencesResult.IsSuccess)
                {
                    return(BoxResponseFactory.CreateError <BoxResponse>(stockDifferencesResult), stockDifferencesResult);
                }

                // BOX 商品を POS 商品に変換し、
                // 取引開始時と比較して、在庫数に差異がある POS 商品を抽出します。
                var items = stockReferrences
                            .Select(arg => (arg.SkuCode, arg.Quantity))
                            .ToArray();

                (var posItemsResult, var posItems) = await BoxItemsToPosItemsAsync(terminal.CompanyCode, terminal.StoreCode, items, skuRepo);

                if (!posItemsResult.IsSuccess)
                {
                    return(BoxResponseFactory.CreateError <BoxResponse>(posItemsResult), posItemsResult);
                }

                var changedPosItems = posItems
                                      .Where(arg => arg.Quantity != 0)
                                      .Select(arg => (arg.ItemCode, 0 < arg.Quantity ? 1 : 2, Math.Abs(arg.Quantity)))
                                      .ToArray();

                if (changedPosItems.Any())
                {
                    // 取引を確定します。
                    var subtotalResult = await cartRepo.SubtotalAsync(box.CartId, changedPosItems);

                    if (!subtotalResult.IsSuccess)
                    {
                        return(BoxResponseFactory.CreateError <BoxResponse>(subtotalResult), subtotalResult);
                    }

                    var createPaymentResult = await cartRepo.CreatePaymentsAsync(box.CartId, new[] { ("01", 0M) });