Пример #1
0
        public async Task Should_Return_No_Deliveries(string producerId, bool available, DeliveryKind kind)
        {
            var token = CancellationToken.None;

            _currentUserService.Setup(c => c.GetCurrentUserInfo()).Returns(Result <RequestUser> .Success(new RequestUser()));

            await _context.AddAsync(new DeliveryMode(
                                        Guid.NewGuid(),
                                        kind,
                                        new Producer(Guid.Parse("3b5c008bb6a24f5c8cc8258b9e33105f"), "prod1", "fa", "la", "*****@*****.**", new UserAddress("x", null, "x", "x", CountryIsoCode.FR, null)),
                                        available,
                                        new DeliveryAddress("x", null, "x", "x", CountryIsoCode.FR, null, null),
                                        new List <DeliveryHours>
            {
                new DeliveryHours(DayOfWeek.Wednesday, TimeSpan.FromHours(8), TimeSpan.FromHours(12))
            },
                                        "delivery1"), token);

            await _context.SaveChangesAsync(token);

            //test
            var results = await _queries.GetNextDeliveries(
                new List <Guid> {
                Guid.Parse(producerId)
            },
                new List <DeliveryKind> {
                DeliveryKind.Farm
            },
                // DateTime.UtcNow,
                _context,
                token);

            //assert
            results.Should().NotBeNull().And.BeEmpty();
        }
Пример #2
0
        public async Task Consume(ConsumeContext <CustomerRegisteredEvent> context)
        {
            var customer = new Customer()
            {
                Id           = context.Message.Id,
                FirstName    = context.Message.FirstName,
                LastName     = context.Message.LastName,
                NationalCode = context.Message.NationalCode,
            };

            _queryDbContext.Customers.Add(customer);
            await _queryDbContext.SaveChangesAsync();
        }
Пример #3
0
        public async Task <int> CreateQueryAsync(TinyQuery tQuery)
        {
            var query = new Query {
                Title       = tQuery.Title,
                Description = tQuery.Description,
                Script      = tQuery.Script,
                UserName    = tQuery.UserName
            };

            _context.Queries.Add(query);
            await _context.SaveChangesAsync();

            return(query.QueryId);
        }
Пример #4
0
        private async Task UpdateOrderReport(CreateOrderEvent notification)
        {
            var monthTime = notification.Time.GetMonthStart();
            var report    = await _queryDbContext.OrderReports.FirstOrDefaultAsync(o => o.MonthTime == monthTime);

            var isUpdate = report != null;

            if (report == null)
            {
                report = new OrderReportEntity
                {
                    Id              = Guid.NewGuid().ToString(),
                    MonthTime       = monthTime,
                    TotalAmount     = 0,
                    TotalCustomer   = 0,
                    TotalOrderCount = 0
                }
            }
            ;

            report.TotalAmount     += notification.OrderItems.Sum(o => o.Quantity * o.UnitPrice);
            report.TotalOrderCount += 1;
            report.LastUpdatedTime  = DateTime.UtcNow;

            if (!await _queryDbContext.CustomerReports.AnyAsync(o => o.MonthTime == monthTime &&
                                                                o.CustomerId == notification.CustomerId))
            {
                report.TotalCustomer += 1;
            }

            if (!isUpdate)
            {
                _queryDbContext.Add(report);
            }

            await _queryDbContext.SaveChangesAsync();
        }
Пример #5
0
        public async Task <IActionResult> RegisteredOfficeHasQuery(Queries query)
        {
            //Code to check if there exist a Query with same ref number
            var QueryExits = context.Queries.Where(q => q.applicationRef == query.applicationRef && q.tableName == "Step2");

            if (QueryExits.Count() > 0)
            {
                if (query.HasQuery == true)
                {
                    //If it exists and has another query Update the current
                    Queries queryExists = QueryExits.FirstOrDefault();
                    queryExists.QueryCount += 1;
                    queryExists.comment     = query.comment;
                    queryExists.status      = "Pending";


                    context.Queries.Update(queryExists);
                    await context.SaveChangesAsync();

                    var forqueryhistory = new QueryHistory()
                    {
                        applicationRef = query.applicationRef,
                        comment        = query.comment,
                        dateCreated    = DateTime.Now.ToString(),
                        status         = "Pending",
                        tableName      = "Step2",
                    };
                    context.QueryHistory.Add(forqueryhistory);
                    await context.SaveChangesAsync();

                    return(Ok());
                }
                else
                {
                    var queryExists = QueryExits.FirstOrDefault();
                    queryExists.status   = "Resolved";
                    queryExists.HasQuery = false;
                    context.Queries.Update(queryExists);
                    await context.SaveChangesAsync();

                    //Updating the Query History Table
                    var forqueryhistory = new QueryHistory()
                    {
                        applicationRef = query.applicationRef,
                        comment        = query.comment,
                        dateCreated    = DateTime.Now.ToString(),
                        status         = "Resolved",
                        tableName      = "Step2",
                    };
                    context.QueryHistory.Add(forqueryhistory);
                    await context.SaveChangesAsync();

                    return(Ok());
                }
            }
            else
            {
                if (query.HasQuery == true)
                {
                    query.status      = "Pending";
                    query.dateCreated = DateTime.Now.ToString();
                    query.QueryCount += 1;
                    query.tableName   = "Step2";
                    context.Queries.Add(query);
                    await context.SaveChangesAsync();

                    var forqueryhistory = new QueryHistory()
                    {
                        applicationRef = query.applicationRef,
                        comment        = query.comment,
                        dateCreated    = DateTime.Now.ToString(),
                        status         = "Pending",
                        tableName      = "Step2",
                    };
                    context.QueryHistory.Add(forqueryhistory);
                    await context.SaveChangesAsync();

                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }