public override void OnCreating(InternalTransferOrder model)
        {
            if (model.InternalTransferOrderDetails.Count > 0)
            {
                InternalTransferOrderDetailService internalTransferOrderDetailService = this.ServiceProvider.GetService <InternalTransferOrderDetailService>();
                internalTransferOrderDetailService.Username = this.Username;
                foreach (InternalTransferOrderDetail detail in model.InternalTransferOrderDetails)
                {
                    internalTransferOrderDetailService.OnCreating(detail);
                }
            }

            base.OnCreating(model);
            model._CreatedAgent      = "Service";
            model._CreatedBy         = this.Username;
            model._LastModifiedAgent = "Service";
            model._LastModifiedBy    = this.Username;
        }
        public override async Task <int> DeleteModel(int Id)
        {
            InternalTransferOrderDetailService internalTransferOrderDetailService = this.ServiceProvider.GetService <InternalTransferOrderDetailService>();

            int Deleted = 0;

            using (var transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    InternalTransferOrder Model = await this.ReadModelById(Id);

                    Deleted = await this.DeleteAsync(Id);

                    HashSet <int> internalTransferOrderDetails = new HashSet <int>(internalTransferOrderDetailService.DbSet
                                                                                   .Where(p => p.ITOId.Equals(Id))
                                                                                   .Select(p => p.Id));

                    internalTransferOrderDetailService.Username = this.Username;

                    foreach (int detail in internalTransferOrderDetails)
                    {
                        await internalTransferOrderDetailService.DeleteModel(detail);
                    }

                    foreach (var detail in Model.InternalTransferOrderDetails)
                    {
                        TransferRequestDetail trd = this.DbContext.TransferRequestDetails.FirstOrDefault(s => s.Id == detail.TRDetailId);
                        trd.Status = "Belum diterima Pembelian";
                    }
                    this.DbContext.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                }
            }

            return(Deleted);
        }