public override async Task <int> UpdateModel(int Id, TransferRequest Model)
        {
            TransferRequestDetailService transferRequestDetailService = this.ServiceProvider.GetService <TransferRequestDetailService>();

            transferRequestDetailService.Username = this.Username;


            int Updated = 0;

            using (var transaction = this.DbContext.Database.BeginTransaction())
            {
                try
                {
                    HashSet <int> transferRequestDetails = new HashSet <int>(transferRequestDetailService.DbSet
                                                                             .Where(w => w.TransferRequestId.Equals(Id))
                                                                             .Select(s => s.Id));
                    Updated = await this.UpdateAsync(Id, Model);


                    foreach (int transferRequestDetail in transferRequestDetails)
                    {
                        TransferRequestDetail model = Model.TransferRequestDetails.FirstOrDefault(prop => prop.Id.Equals(transferRequestDetail));
                        if (model == null)
                        {
                            await transferRequestDetailService.DeleteModel(transferRequestDetail);
                        }
                        else
                        {
                            await transferRequestDetailService.UpdateModel(transferRequestDetail, model);
                        }
                    }

                    foreach (TransferRequestDetail transferRequestDetail in Model.TransferRequestDetails)
                    {
                        if (transferRequestDetail.Id.Equals(0))
                        {
                            await transferRequestDetailService.CreateModel(transferRequestDetail);
                        }
                    }


                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                }
            }

            return(Updated);
        }
        public override void OnCreating(TransferRequest model)
        {
            if (model.TransferRequestDetails.Count > 0)
            {
                TransferRequestDetailService transferRequestDetailService = this.ServiceProvider.GetService <TransferRequestDetailService>();

                transferRequestDetailService.Username = this.Username;
                foreach (TransferRequestDetail transferRequestDetail in model.TransferRequestDetails)
                {
                    transferRequestDetailService.OnCreating(transferRequestDetail);
                }
            }

            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)
        {
            TransferRequestDetailService transferRequestDetailService = this.ServiceProvider.GetService <TransferRequestDetailService>();

            int Deleted = 0;

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

                    Deleted = await this.DeleteAsync(Id);

                    HashSet <int> transferRequestDetails = new HashSet <int>(transferRequestDetailService.DbSet
                                                                             .Where(p => p.TransferRequestId.Equals(Id))
                                                                             .Select(p => p.Id));

                    transferRequestDetailService.Username = this.Username;

                    foreach (int transferRequestDetail in transferRequestDetails)
                    {
                        await transferRequestDetailService.DeleteModel(transferRequestDetail);
                    }


                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                }
            }

            return(Deleted);
        }