Ejemplo n.º 1
0
 public Task UpdateAsync(
     StockArrival arrival,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PatchAsync(_host + "/Stock/Arrivals/v1/Update", null, arrival, headers, ct));
 }
Ejemplo n.º 2
0
        public async Task <Guid> CreateAsync(Guid userId, StockArrival arrival, CancellationToken ct)
        {
            var newStockArrival = new StockArrival();

            var change = newStockArrival.CreateWithLog(userId, x =>
            {
                x.Id             = arrival.Id;
                x.AccountId      = arrival.AccountId;
                x.CreateUserId   = userId;
                x.Type           = arrival.Type;
                x.SupplierId     = arrival.SupplierId;
                x.OrderId        = arrival.OrderId;
                x.InventoryId    = arrival.InventoryId;
                x.IsDeleted      = arrival.IsDeleted;
                x.CreateDateTime = DateTime.UtcNow;
                x.Items          = arrival.Items.Map(x.Id);
            });

            var entry = await _storage.AddAsync(newStockArrival, ct);

            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);

            return(entry.Entity.Id);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <Guid> > Create(StockArrival arrival, CancellationToken ct = default)
        {
            arrival.AccountId = _userContext.AccountId;

            var id = await _stockArrivalsService.CreateAsync(_userContext.UserId, arrival, ct);

            return(Created(nameof(Get), id));
        }
Ejemplo n.º 4
0
 public StockArrivalBuilder(
     IDefaultRequestHeadersService defaultRequestHeadersService,
     IStockArrivalsClient arrivalsClient)
 {
     _arrivalsClient = arrivalsClient;
     _defaultRequestHeadersService = defaultRequestHeadersService;
     _arrival = new StockArrival
     {
         Id        = Guid.NewGuid(),
         Type      = StockArrivalType.ArrivalFromSupplier,
         IsDeleted = false
     };
 }
Ejemplo n.º 5
0
        public async Task <ActionResult> Update(StockArrival arrival, CancellationToken ct = default)
        {
            var oldArrival = await _stockArrivalsService.GetAsync(arrival.Id, true, ct);

            if (oldArrival == null)
            {
                return(NotFound(arrival.Id));
            }

            return(await ActionIfAllowed(
                       () => _stockArrivalsService.UpdateAsync(_userContext.UserId, oldArrival, arrival, ct),
                       Roles.Stock,
                       oldArrival.AccountId));
        }
Ejemplo n.º 6
0
        public static StockArrivalChange CreateWithLog(
            this StockArrival arrival,
            Guid userId,
            Action <StockArrival> action)
        {
            action(arrival);

            return(new StockArrivalChange
            {
                StockArrivalId = arrival.Id,
                ChangerUserId = userId,
                CreateDateTime = DateTime.UtcNow,
                OldValueJson = string.Empty,
                NewValueJson = arrival.ToJsonString()
            });
        }
Ejemplo n.º 7
0
 public static bool FilterByAdditional(this StockArrival arrival, StockArrivalGetPagedListRequest request)
 {
     return((request.Types == null || !request.Types.Any() ||
             request.Types.Any(x => TypesPredicate(arrival, x))) &&
            (request.CreateUserIds == null || !request.CreateUserIds.Any() ||
             request.CreateUserIds.Any(x => CreateUserIdsPredicate(arrival, x))) &&
            (request.SupplierIds == null || !request.SupplierIds.Any() ||
             request.SupplierIds.Any(x => SupplierIdsPredicate(arrival, x))) &&
            (request.OrderIds == null || !request.OrderIds.Any() ||
             request.OrderIds.Any(x => OrderIdsPredicate(arrival, x))) &&
            (request.InventoryIds == null || !request.InventoryIds.Any() ||
             request.InventoryIds.Any(x => InventoryIdsPredicate(arrival, x))) &&
            (request.ItemsRoomIds == null || !request.ItemsRoomIds.Any() ||
             request.ItemsRoomIds.Any(x => ItemsRoomIdsPredicate(arrival, x))) &&
            (request.ItemsProductIds == null || !request.ItemsProductIds.Any() ||
             request.ItemsProductIds.Any(x => ItemsProductIdsPredicate(arrival, x))));
 }
Ejemplo n.º 8
0
        public async Task UpdateAsync(
            Guid userId,
            StockArrival oldArrival,
            StockArrival newArrival,
            CancellationToken ct)
        {
            var change = oldArrival.UpdateWithLog(userId, x =>
            {
                x.AccountId      = newArrival.AccountId;
                x.Type           = newArrival.Type;
                x.SupplierId     = newArrival.SupplierId;
                x.OrderId        = newArrival.OrderId;
                x.InventoryId    = newArrival.InventoryId;
                x.IsDeleted      = newArrival.IsDeleted;
                x.ModifyDateTime = DateTime.UtcNow;
                x.Items          = newArrival.Items.Map(x.Id);
            });

            _storage.Update(oldArrival);
            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);
        }
Ejemplo n.º 9
0
 private static bool ItemsProductIdsPredicate(StockArrival arrival, Guid id)
 {
     return(arrival.Items == null || !arrival.Items.Any() ||
            arrival.Items.Any(x => x.ProductId == id));
 }
Ejemplo n.º 10
0
 private static bool CreateUserIdsPredicate(StockArrival arrival, Guid id)
 {
     return(arrival.CreateUserId == id);
 }
Ejemplo n.º 11
0
 private static bool InventoryIdsPredicate(StockArrival arrival, Guid id)
 {
     return(arrival.InventoryId == id);
 }
Ejemplo n.º 12
0
 private static bool OrderIdsPredicate(StockArrival arrival, Guid id)
 {
     return(arrival.OrderId == id);
 }
Ejemplo n.º 13
0
 private static bool SupplierIdsPredicate(StockArrival arrival, Guid id)
 {
     return(arrival.SupplierId == id);
 }
Ejemplo n.º 14
0
 private static bool TypesPredicate(StockArrival arrival, StockArrivalType type)
 {
     return(arrival.Type == type);
 }