Пример #1
0
        public async Task <CheckInOutput> ExecuteNewPrice(CheckInInput input)
        {
            var part = await this._partRepository.GetEntityAsync(e => e.Id == input.PartId);

            if (part != null)
            {
                input.PartInstance.PartId = input.PartId;
                input.PartInstance.Price  = input.Price;

                input.PartInstance.UpdatePrice();
                var instanceEntity = await this._partInstanceRepository.AddAsync(input.PartInstance);

                if (instanceEntity != null)
                {
                    PartPrice partPrice = new PartPrice(part, instanceEntity.Price);
                    PriceLog  priceLog  = new PriceLog(instanceEntity, instanceEntity.Price);
                    await this._partPriceRepository.AddAsync(partPrice);

                    await this._priceLogRepository.AddAsync(priceLog);

                    Transaction transaction = new Transaction();
                    transaction.SetupCheckIn(instanceEntity, InventoryAction.INCOMING, instanceEntity.LocationId, input.TimeStamp);
                    transaction.SessionId = this._userService.CurrentSessionId.Value;
                    var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == instanceEntity.StockTypeId);

                    if (stockType != null)
                    {
                        if (!stockType.IsDefault)
                        {
                            if (stockType != null)
                            {
                                if (instanceEntity.IsBubbler)
                                {
                                    stockType.Quantity += (int)instanceEntity.BubblerParameter.Weight;
                                }
                                else
                                {
                                    stockType.Quantity += instanceEntity.Quantity;
                                }
                                await this._categoryRepository.UpdateAsync(stockType);
                            }
                        }
                        else
                        {
                            IndividualAlert alert = new IndividualAlert();
                            alert.PartInstance             = instanceEntity;
                            instanceEntity.IndividualAlert = alert;
                            this._context.Add(alert);
                        }
                    }
                    else
                    {
                        await this._unitOfWork.Undo();

                        return(new CheckInOutput(null, false, "Error: Could not adjust stock, Please contact administrator"));
                    }


                    var tranEntity = await this._transactionRepository.AddAsync(transaction);

                    var count = await this._unitOfWork.Save();

                    if (count > 0)
                    {
                        return(new CheckInOutput(instanceEntity, true, "Part Checked In!"));
                    }
                    else
                    {
                        await this._unitOfWork.Undo();

                        return(new CheckInOutput(null, false, "Error: Check in Failed"));
                    }
                }
                else
                {
                    await this._unitOfWork.Undo();

                    return(new CheckInOutput(null, false, "Error: Could Not Create Part Instance"));
                }
            }
            else
            {
                await this._unitOfWork.Undo();

                return(new CheckInOutput(null, false, "Error: Part Not Found"));
            }
        }
Пример #2
0
        public async Task <PriceEditOutput> ExecuteNew(PriceEditInput input)
        {
            var part = await this._partRepository.GetEntityAsync(e => e.Id == input.PartId);

            if (part == null)
            {
                return(new PriceEditOutput(null, false, "Error: Part Not Found"));
            }

            Price price = new Price();

            price.LeadTime      = input.LeadTime;
            price.MinOrder      = input.MinOrder;
            price.TimeStamp     = input.TimeStamp;
            price.UnitCost      = input.UnitCost;
            price.ValidFrom     = input.ValidFrom;
            price.ValidUntil    = input.ValidUntil;
            price.DistributorId = input.DistributorId;

            if (input.PartInstanceId.HasValue)
            {
                var partInstance = await this._partInstanceRepository.GetEntityAsync(e => e.Id == input.PartInstanceId.Value);

                if (partInstance != null)
                {
                    price.PartInstances.Add(partInstance);
                    partInstance.UnitCost = price.UnitCost;
                    if (partInstance.IsBubbler)
                    {
                        partInstance.TotalCost = (price.UnitCost * partInstance.BubblerParameter.NetWeight) * partInstance.Quantity;
                    }
                    else
                    {
                        partInstance.TotalCost = price.UnitCost * partInstance.Quantity;
                    }
                    PriceLog priceLog = new PriceLog(partInstance, price);
                    await this._priceLogRepository.AddAsync(priceLog);

                    await this._partInstanceRepository.UpdateAsync(partInstance);
                }
                else
                {
                    return(new PriceEditOutput(null, false, "Error: PartInstance Not Found"));
                }
            }
            else
            {
                return(new PriceEditOutput(null, false, "Error: PartInstance Not Found"));
            }

            var priceAdded = await this._priceRepository.AddAsync(price);

            PartPrice partPrice      = new PartPrice(part, price);
            var       partPriceAdded = await this._partPriceRepository.AddAsync(partPrice);

            if (priceAdded != null && partPriceAdded != null)
            {
                var count = await this._unitOfWork.Save();

                return(new PriceEditOutput(priceAdded, true, "Price Added and Saved"));
            }
            else
            {
                await this._unitOfWork.Undo();

                return(new PriceEditOutput(null, false, "Error: New Price Save Failed"));
            }
        }