public override void OnCreating(StockTransferNote model)
        {
            base.OnCreating(model);

            model._CreatedAgent      = "Service";
            model._CreatedBy         = this.Username;
            model._LastModifiedAgent = "Service";
            model._LastModifiedBy    = this.Username;

            StockTransferNote_ItemService stockTransferNoteItemService = ServiceProvider.GetService <StockTransferNote_ItemService>();

            stockTransferNoteItemService.Username = this.Username;

            foreach (StockTransferNote_Item stni in model.StockTransferNoteItems)
            {
                stockTransferNoteItemService.OnCreating(stni);
            }
        }
        public override async Task <int> DeleteModel(int Id)
        {
            int Count = 0;

            using (var Transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    StockTransferNote stockTransferNote = await ReadModelById(Id);

                    Count = this.Delete(Id);

                    StockTransferNoteService      stockTransferNoteService     = ServiceProvider.GetService <StockTransferNoteService>();
                    StockTransferNote_ItemService stockTransferNoteItemService = ServiceProvider.GetService <StockTransferNote_ItemService>();
                    stockTransferNoteItemService.Username = this.Username;

                    HashSet <int> StockTransferNoteItems = new HashSet <int>(this.DbContext.StockTransferNoteItems.Where(p => p.StockTransferNote.Equals(Id)).Select(p => p.Id));

                    foreach (int item in StockTransferNoteItems)
                    {
                        await stockTransferNoteItemService.DeleteAsync(item);
                    }

                    CreateInventoryDocument(stockTransferNote, "IN", "DELETE-SOURCE");

                    Transaction.Commit();
                }
                catch (DbUpdateConcurrencyException)
                {
                    Transaction.Rollback();
                    throw;
                }
            }

            return(Count);
        }