Ejemplo n.º 1
0
        public int UpdateEntityDirectReport(EntityDirectReportDTO message)
        {
            using (var projectContext = new DataAccess.MyProjectEntities())
            {
                //BizEntityReport bizEntityReport = new MyModelManager.BizEntityReport();
                BizEntityDataItemReport bizEntityDataItemReport = new BizEntityDataItemReport();
                var dbEntitySpecifiedReport = projectContext.EntityDirectlReport.FirstOrDefault(x => x.ID == message.ID);
                if (dbEntitySpecifiedReport == null)
                {
                    message.ReportType      = ReportType.DataItemReport;
                    dbEntitySpecifiedReport = new EntityDirectlReport();
                    dbEntitySpecifiedReport.EntityDataItemReport = bizEntityDataItemReport.ToNewEntityDataItemReport(message);
                    dbEntitySpecifiedReport.EntityDataItemReport.DataItemReportType = (short)DataItemReportType.DirectReport;
                }
                else
                {
                    bizEntityDataItemReport.ToUpdateEntityDataItemReport(dbEntitySpecifiedReport.EntityDataItemReport, message);
                }

                dbEntitySpecifiedReport.URL = message.URL;
                while (dbEntitySpecifiedReport.EntityDirectlReportParameters.Any())
                {
                    projectContext.EntityDirectlReportParameters.Remove(dbEntitySpecifiedReport.EntityDirectlReportParameters.First());
                }
                foreach (var item in message.EntityDirectlReportParameters)
                {
                    dbEntitySpecifiedReport.EntityDirectlReportParameters.Add(new EntityDirectlReportParameters()
                    {
                        ColumnID      = item.ColumnID,
                        ParameterName = item.ParameterName
                    });
                }
                if (dbEntitySpecifiedReport.ID == 0)
                {
                    projectContext.EntityDirectlReport.Add(dbEntitySpecifiedReport);
                }
                projectContext.SaveChanges();
                return(dbEntitySpecifiedReport.ID);
            }
        }
Ejemplo n.º 2
0
        public int UpdateGraph(GraphDTO message)
        {
            using (var projectContext = new DataAccess.MyProjectEntities())
            {
                BizEntityDataItemReport bizEntityDataItemReport = new BizEntityDataItemReport();

                var dbEntity = projectContext.GraphDefinition.FirstOrDefault(x => x.ID == message.ID);
                if (dbEntity == null)
                {
                    message.ReportType            = ReportType.DataItemReport;
                    dbEntity                      = new GraphDefinition();
                    dbEntity.EntityDataItemReport = bizEntityDataItemReport.ToNewEntityDataItemReport(message);
                    dbEntity.EntityDataItemReport.DataItemReportType = (short)DataItemReportType.GraphReport;
                }
                else
                {
                    bizEntityDataItemReport.ToUpdateEntityDataItemReport(dbEntity.EntityDataItemReport, message);
                }

                if (message.FirstSideDataMenuID != 0)
                {
                    dbEntity.FirstSideDataMenuID = message.FirstSideDataMenuID;
                }
                else
                {
                    dbEntity.FirstSideDataMenuID = null;
                }

                dbEntity.NotJointEntities = message.NotJointEntities;
                while (dbEntity.GraphDefinition_EntityRelationshipTail.Any())
                {
                    projectContext.GraphDefinition_EntityRelationshipTail.Remove(dbEntity.GraphDefinition_EntityRelationshipTail.First());
                }
                foreach (var item in message.RelationshipsTails)
                {
                    var dbRel = new GraphDefinition_EntityRelationshipTail();
                    dbRel.EntityRelationshipTailID = item.RelationshipTailID;

                    if (item.EntityRelationshipTailDataMenuID != 0)
                    {
                        dbRel.EntityRelationshipTailDataMenuID = item.EntityRelationshipTailDataMenuID;
                    }

                    //   dbRel.FromFirstSideToSecondSide = item.FromFirstSideToSecondSide;
                    dbEntity.GraphDefinition_EntityRelationshipTail.Add(dbRel);
                }

                if (dbEntity.ID == 0)
                {
                    projectContext.GraphDefinition.Add(dbEntity);
                }
                try
                {
                    projectContext.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    throw e;
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
                catch (Exception ex)
                {
                    //result.Result = Enum_DR_ResultType.ExceptionThrown;
                    //result.Message = "خطا در ثبت" + Environment.NewLine + ex.Message;
                }
                return(dbEntity.ID);
            }
        }