public Procurementcontract CreateProcurementcontract(Procurementcontract info, List<Procurementcontractdetail> detailInfos)
 {
     var coderuleManagement = new CoderuleManagement(Management);
     info.Contractid = coderuleManagement.GenerateCodeRule(Procurementcontract.RuleCode+DateTime.Today.ToString("yyyyMM"), false);
     foreach (var detailInfo in detailInfos)
     {
         detailInfo.Contractid = info.Contractid;
     }
     var detailManagement = new ProcurementcontractdetailManagement(Management);
     try
     {
         Management.BeginTransaction();
         Management.CreateProcurementcontract(info);
         foreach (var detailInfo in detailInfos)
         {
             detailManagement.CreateProcurementcontractdetail(detailInfo);
         }
         Management.Commit();
     }
     catch
     {
         Management.Rollback();
         throw;
     }
     return info;
 }
 public void DeleteProcurementcontractByContractid(string contractid)
 {
     try
     {
         var detailManagement=new ProcurementcontractdetailManagement(Management);
         Management.BeginTransaction();
         detailManagement.DeleteProcurementcontractdetailsByContractid(new List<string>(){contractid});
         Management.DeleteProcurementcontractByContractid(contractid);
         Management.Commit();
     }
     catch
     {
         Management.Rollback();
         throw;
     }
 }
        public Procurementcontract UpdateProcurementcontractByContractid(Procurementcontract info, List<Procurementcontractdetail> detailInfos)
        {
            foreach (var detailInfo in detailInfos)
            {
                detailInfo.Contractid = info.Contractid;
            }
            var detailManagement = new ProcurementcontractdetailManagement(Management);

            var dbContractDetails = detailManagement.RetrieveProcurementcontractdetailListByContractid(info.Contractid);

            try
            {
                Management.BeginTransaction();
                Management.UpdateProcurementcontractByContractid(info);

                foreach (var detail in detailInfos)
                {
                    var existInfo = dbContractDetails.Where(p => p.Contractdetailid == detail.Contractdetailid).FirstOrDefault();

                    if (existInfo == null)
                    {
                        detailManagement.CreateProcurementcontractdetail(detail);
                    }
                    else
                    {
                        detailManagement.UpdateProcurementcontractdetailByContractdetailid(detail);
                    }
                }
                Management.Commit();
            }
            catch
            {
                Management.Rollback();
                throw;
            }
            return info;
        }