コード例 #1
0
        private async Task <CheckOutOutputData> ExecuteStandard(PartInstance partInstance, Location location, CheckOutInputData item)
        {
            partInstance.UpdateQuantity(0 - item.Quantity);
            if (item.ConditionId != 0)
            {
                var condition = await this._categoryRepository.GetEntityAsync(e => e.Id == item.ConditionId);

                if (condition != null)
                {
                    partInstance.ConditionId = condition.Id;
                }
            }
            Transaction transaction = new Transaction(partInstance, InventoryAction.OUTGOING,
                                                      0, 0, location, item.TimeStamp);

            transaction.Quantity  = item.Quantity;
            transaction.UnitCost  = item.UnitCost;
            transaction.TotalCost = item.Quantity * item.UnitCost;

            if (!partInstance.StockType.IsDefault)
            {
                var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == partInstance.StockType.Id);

                if (stockType != null)
                {
                    stockType.Quantity -= item.Quantity;
                    await this._categoryRepository.UpdateAsync(stockType);
                }
                else
                {
                    return(new CheckOutOutputData(null, false, "Error:  Could not adjust stock, Please contact administrator"));
                }
            }

            transaction.SessionId = this._userService.CurrentSessionId.Value;
            var instance = await this._partInstanceRepository.UpdateAsync(partInstance);

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

            StringBuilder builder = new StringBuilder();

            if (instance != null && trans != null)
            {
                var val = await this._unitOfWork.Save();

                builder.AppendFormat("Instance: {0} Quantity:{1} LinesUpdated: {2}", instance.Name, transaction.Quantity, val).AppendLine();
                return(new CheckOutOutputData(trans, true, builder.ToString()));
            }
            else
            {
                await this._unitOfWork.Undo();

                builder.AppendFormat("Instance: {0}", partInstance.Name).AppendLine();
                return(new CheckOutOutputData(transaction, false, builder.ToString()));
            }
        }
コード例 #2
0
        private async Task <TransactionUndoOutput> ExecuteUndoAddTo(PartInstance partInstance, Transaction transaction)
        {
            var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == partInstance.StockTypeId);

            if (stockType != null)
            {
                partInstance.UpdateQuantity(0 - transaction.Quantity);
                if (!stockType.IsDefault)
                {
                    stockType.Quantity -= transaction.Quantity;
                }
                var instance = await this._partInstanceRepository.UpdateAsync(partInstance);

                var trans = await this._transactionRepository.DeleteAsync(transaction);

                var updated = await this._categoryRepository.UpdateAsync(stockType);

                if (updated != null && instance != null && trans != null)
                {
                    var count = await this._unitOfWork.Save();

                    if (count > 0)
                    {
                        return(new TransactionUndoOutput(null, true, "Success: Transaction Successfully Undone"));
                    }
                    else
                    {
                        await this._unitOfWork.Undo();

                        return(new TransactionUndoOutput(null, false, "Internal Error: Could not save"));
                    }
                }
                else
                {
                    await this._unitOfWork.Undo();

                    return(new TransactionUndoOutput(null, false, "Internal Error: Could not update Entities"));
                }
            }
            else
            {
                await this._unitOfWork.Undo();

                return(new TransactionUndoOutput(null, false, "Internal Error: Could not find Stock type"));
            }
        }
コード例 #3
0
        private async Task <ReturnItemOutput> ExecuteBubbler(PartInstance partInstance, Location location, Transaction refTransaction, ReturnItemInput item)
        {
            partInstance.UpdateWeight(item.MeasuredWeight);
            //partInstance.BubblerParameter.DateRemoved = item.TimeStamp;
            partInstance.UpdateQuantity(1);
            partInstance.CostReported = false;
            partInstance.LocationId   = location.Id;
            partInstance.DateRemoved  = item.TimeStamp;
            if (item.ConditionId != 0)
            {
                var condition = await this._categoryRepository.GetEntityAsync(e => e.Id == item.ConditionId);

                if (condition != null)
                {
                    partInstance.ConditionId = condition.Id;
                }
            }

            if (!partInstance.StockType.IsDefault)
            {
                var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == partInstance.StockTypeId);

                if (stockType != null)
                {
                    stockType.Quantity += (int)partInstance.BubblerParameter.Weight;
                    var updated = await this._categoryRepository.UpdateAsync(stockType);

                    if (updated == null)
                    {
                        await this._unitOfWork.Undo();

                        return(new ReturnItemOutput(null, false, "Error: Could not adjust stock, Please contact administrator"));
                    }
                }
                else
                {
                    await this._unitOfWork.Undo();

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

            Transaction transaction = new Transaction(partInstance, InventoryAction.RETURNING,
                                                      partInstance.BubblerParameter.Measured, partInstance.BubblerParameter.Weight, location, item.TimeStamp);

            transaction.UnitCost  = 0;
            transaction.TotalCost = 0;
            transaction.ReferenceTransactionId = refTransaction.Id;
            transaction.SessionId = this._userService.CurrentSessionId.Value;

            var bubbler = await this._bubblerRepository.UpdateAsync(partInstance.BubblerParameter);

            var instance = await this._partInstanceRepository.UpdateAsync(partInstance);

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

            StringBuilder builder = new StringBuilder();

            if (bubbler != null && instance != null && trans != null)
            {
                var val = await this._unitOfWork.Save();

                builder.AppendFormat("Instance: {0} Weight: {1} LinesUpdated: {2}", instance.Name, bubbler.Weight, val).AppendLine();
                return(new ReturnItemOutput(trans, true, builder.ToString()));
            }
            else
            {
                await this._unitOfWork.Undo();

                builder.AppendFormat("Instance: {0}", partInstance.Name).AppendLine();
                return(new ReturnItemOutput(transaction, false, builder.ToString()));
            }
        }
コード例 #4
0
        private async Task <CheckOutOutputData> ExecuteBubbler(PartInstance partInstance, Location location, CheckOutInputData item)
        {
            partInstance.UpdateWeight(item.MeasuredWeight);
            partInstance.DateInstalled = item.TimeStamp;
            partInstance.DateRemoved   = null;
            partInstance.UpdateQuantity(-1);
            partInstance.CostReported = false;
            partInstance.LocationId   = location.Id;

            if (item.ConditionId != 0)
            {
                var condition = await this._categoryRepository.GetEntityAsync(e => e.Id == item.ConditionId);

                if (condition != null)
                {
                    partInstance.ConditionId = condition.Id;
                }
            }

            if (!partInstance.StockType.IsDefault)
            {
                var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == partInstance.StockType.Id);

                if (stockType != null)
                {
                    stockType.Quantity -= (int)partInstance.BubblerParameter.Weight;
                    await this._categoryRepository.UpdateAsync(stockType);
                }
                else
                {
                    return(new CheckOutOutputData(null, false, "Error:  Could not adjust stock, Please contact administrator"));
                }
            }

            Transaction transaction = new Transaction(partInstance, InventoryAction.OUTGOING,
                                                      partInstance.BubblerParameter.Measured, partInstance.BubblerParameter.Weight, location, item.TimeStamp);

            transaction.SessionId = this._userService.CurrentSessionId.Value;
            var bubbler = await this._bubblerRepository.UpdateAsync(partInstance.BubblerParameter);

            var instance = await this._partInstanceRepository.UpdateAsync(partInstance);

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

            StringBuilder builder = new StringBuilder();

            if (bubbler != null && instance != null && trans != null)
            {
                var stockType = await this._context.Categories.OfType <StockType>().Include(e => e.PartInstances).FirstOrDefaultAsync(e => e.Id == instance.Id);

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

                builder.AppendFormat("Instance: {0} Weight: {1} LinesUpdated: {2}", instance.Name, bubbler.Weight, val).AppendLine();
                return(new CheckOutOutputData(trans, true, builder.ToString()));
            }
            else
            {
                await this._unitOfWork.Undo();

                builder.AppendFormat("Instance: {0}", partInstance.Name).AppendLine();
                return(new CheckOutOutputData(transaction, false, builder.ToString()));
            }
        }
コード例 #5
0
        private async Task <TransactionUndoOutput> ExecuteUndoReturn(PartInstance partInstance, Transaction transaction)
        {
            var referenceTransaction = await this._transactionRepository.GetEntityAsync(e => e.Id == transaction.ReferenceTransactionId);

            if (referenceTransaction != null)
            {
                var location = await this._locationRepository.GetEntityAsync(e => e.Id == referenceTransaction.LocationId);

                var stockType = (StockType)await this._categoryRepository.GetEntityAsync(e => e.Id == partInstance.StockTypeId);

                if (stockType != null)
                {
                    if (location != null)
                    {
                        partInstance.LocationId = location.Id;
                    }
                    if (partInstance.IsBubbler)
                    {
                        partInstance.UpdateQuantity(-1);
                        partInstance.UpdateWeight(referenceTransaction.MeasuredWeight);
                        partInstance.DateRemoved = null;
                        if (!stockType.IsDefault)
                        {
                            stockType.Quantity -= (int)partInstance.BubblerParameter.Weight;
                        }
                        var bubbler = await this._bubblerRepository.UpdateAsync(partInstance.BubblerParameter);

                        if (bubbler == null)
                        {
                            await this._unitOfWork.Undo();

                            return(new TransactionUndoOutput(null, false, "Internal Error: Could not update BubblerParameter"));
                        }
                    }
                    else
                    {
                        partInstance.UpdateQuantity(0 - transaction.Quantity);
                        if (!stockType.IsDefault)
                        {
                            stockType.Quantity -= transaction.Quantity;
                        }
                    }
                    var instance = await this._partInstanceRepository.UpdateAsync(partInstance);

                    var trans = await this._transactionRepository.DeleteAsync(transaction);

                    var updated = await this._categoryRepository.UpdateAsync(stockType);

                    if (updated != null && instance != null && trans != null)
                    {
                        var count = await this._unitOfWork.Save();

                        if (count > 0)
                        {
                            return(new TransactionUndoOutput(null, true, "Success: Transaction Successfully Undone"));
                        }
                        else
                        {
                            await this._unitOfWork.Undo();

                            return(new TransactionUndoOutput(null, false, "Internal Error: Could not save"));
                        }
                    }
                    else
                    {
                        await this._unitOfWork.Undo();

                        return(new TransactionUndoOutput(null, false, "Internal Error: Could not update Entities"));
                    }
                }
                else
                {
                    await this._unitOfWork.Undo();

                    return(new TransactionUndoOutput(null, false, "Internal Error: Could not find Stock type"));
                }
            }
            else
            {
                return(new TransactionUndoOutput(null, false, "Internal Error: Could not find ReferenceTransaction"));
            }
        }