当前位置: 首页>>代码示例>>C#>>正文


C# CmsEntities.SaveChanges方法代码示例

本文整理汇总了C#中CmsEntities.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# CmsEntities.SaveChanges方法的具体用法?C# CmsEntities.SaveChanges怎么用?C# CmsEntities.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CmsEntities的用法示例。


在下文中一共展示了CmsEntities.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddElectricalComponentTypeProperty

        public ElectricalEquipmentComponentTypeProperty AddElectricalComponentTypeProperty(ElectricalEquipmentComponentTypeProperty mecp)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                //Check if this component property already exist
                ElectricalEquipmentComponentTypeProperty temp = (from x in cee.ElectricalEquipmentComponentTypeProperties
                                                                 where x.ElectricalEquipmentPropertyId == mecp.ElectricalEquipmentPropertyId &&
                                                                       x.ElectricalEquipmentComponentTypeId == mecp.ElectricalEquipmentComponentTypeId
                                                                 select x).FirstOrDefault();

                if (temp == null)
                {
                    //Add new Component Type
                    temp = new ElectricalEquipmentComponentTypeProperty();
                    temp.ElectricalEquipmentPropertyId = mecp.ElectricalEquipmentPropertyId;
                    temp.ElectricalEquipmentComponentTypeId = mecp.ElectricalEquipmentComponentTypeId;
                    temp.Ordinal = mecp.Ordinal;

                    cee.ElectricalEquipmentComponentTypeProperties.Add(temp);
                    cee.SaveChanges();
                }
                else
                {
                    temp.Ordinal = mecp.Ordinal;
                    cee.SaveChanges();
                }
                return temp;
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:29,代码来源:CmsWebService.Electrical.cs

示例2: SaveIssueFiles

        public DbOperationResult SaveIssueFiles(List<IssueFile> issueFiles)
        {
            try
            {
                using (var cee = new CmsEntities())
                {
                    foreach (IssueFile attachment in issueFiles)
                    {
                        IssueFile existingAttachment = (from x in cee.IssueFiles
                                                        where x.Filename == attachment.Filename &&
                                                              x.Path == attachment.Path
                                                        select x).FirstOrDefault();

                        if (existingAttachment != null)
                        {
                            existingAttachment.Description = attachment.Description;
                        }
                        else
                        {
                            attachment.User = null;
                            attachment.Issue = null;
                            attachment.AttachmentType = null;
                            cee.IssueFiles.Add(attachment);
                        }
                    }
                    cee.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return new DbOperationResult { ServerErrorMessages = new List<string> { ex.Message } };
            }

            return new DbOperationResult();
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:35,代码来源:CmsEmailCorrespondenceSaver.cs

示例3: AddIssueTypeMilestoneType

        public DbOperationResult<IssueTypeMilestoneType> AddIssueTypeMilestoneType(IssueType issueType, IssueMilestoneType milestoneType)
        {
            var result = new DbOperationResult<IssueTypeMilestoneType>();

            //guard against duplicate.
            using (var cee = new CmsEntities())
            {
                int k = (from x in cee.IssueTypeMilestoneTypes where x.IssueTypeId == issueType.Id && x.MilestoneTypeId == milestoneType.Id select x.Id).Count();

                if (k > 0)
                {
                    result.ServerErrorMessages.Add(string.Format("Insert Failed. An IssueTypeMilestoneType with the combination IssueType Name: '{0}' and Issue SubType Name: '{1}' already exists.", issueType.Name, milestoneType.Name));
                    return result;
                }

                var issueTypeMilestoneType = new IssueTypeMilestoneType
                {
                    MilestoneTypeId = milestoneType.Id,
                    IssueTypeId = issueType.Id,
                    Ordinal = 0
                };

                cee.IssueTypeMilestoneTypes.Add(issueTypeMilestoneType);
                cee.SaveChanges();
                result.EntityResult = issueTypeMilestoneType;
            }

            return result;
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:29,代码来源:CmsWebService.Issue.cs

示例4: Fix

        public void Fix()
        {
            CmsEntities cee = new CmsEntities();

            List<IssueRelatedIssue> itemsToAdd = new List<IssueRelatedIssue>();

            var allRelatedIssues = cee.IssueRelatedIssues.ToList();

            foreach (var relatedIssue in allRelatedIssues)
            {
                var reverseExist = (allRelatedIssues.FirstOrDefault(x => x.RelatedIssueId == relatedIssue.IssueId));

                if (reverseExist == null)
                {
                    if (itemsToAdd.FirstOrDefault(x => x.IssueId == relatedIssue.IssueId  && x.RelatedIssueId == relatedIssue.RelatedIssueId) == null)
                    {
                        itemsToAdd.Add(new IssueRelatedIssue {IssueId = relatedIssue.RelatedIssueId, RelatedIssueId = relatedIssue.IssueId});
                    }
                }
            }

            if (itemsToAdd.Any())
            {
                foreach (var issueRelatedIssue in itemsToAdd)
                {
                    cee.IssueRelatedIssues.Add(new IssueRelatedIssue { IssueId = issueRelatedIssue.IssueId, RelatedIssueId = issueRelatedIssue.RelatedIssueId });
                }
            }

            cee.SaveChanges();
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:31,代码来源:FixIssueRelatedIssues.cs

示例5: AddArticle

 /// <summary>
 /// 添加文章
 /// </summary>
 /// <param name="varticle"></param>
 public int AddArticle(cms_varticle varticle)
 {
     using (CmsEntities entity = new CmsEntities())
     {
         cms_varticle obj = varticle;
         entity.cms_varticle.AddObject(obj);
         entity.SaveChanges();
         return obj.id;
     }
 }
开发者ID:91mvc,项目名称:YQCMS,代码行数:14,代码来源:ArticleServiceImpl.cs

示例6: AddControlSystemComponentType

        public ControlSystemComponentType AddControlSystemComponentType(ControlSystemComponentType controlSystemComponentType)
        {
            var newControlSystemComponentType = new ControlSystemComponentType();

            using (var cee = new CmsEntities())
            {
                //Check if this component type already exist
                var componentType = (from x in cee.ControlSystemComponentTypes
                                     where x.Id == controlSystemComponentType.Id
                                     select x).FirstOrDefault();

                if (componentType != null)
                {
                    //Edit the Component Type
                    componentType.Name = controlSystemComponentType.Name;
                    componentType.Description = controlSystemComponentType.Description;
                    componentType.Ordinal = controlSystemComponentType.Ordinal;

                    cee.SaveChanges();
                }
                else
                {
                    //Add new Component Type
                    componentType = new ControlSystemComponentType();
                    componentType.Name = controlSystemComponentType.Name;
                    componentType.Description = controlSystemComponentType.Description;
                    componentType.Code = controlSystemComponentType.Name.Replace(" ", "");
                    componentType.IsActive = true;
                    cee.ControlSystemComponentTypes.Add(componentType);

                    cee.SaveChanges();
                }

                newControlSystemComponentType.Id = componentType.Id;
                newControlSystemComponentType.Name = componentType.Name;
                newControlSystemComponentType.Description = componentType.Description;
                newControlSystemComponentType.Ordinal = componentType.Ordinal;
                newControlSystemComponentType.Code = componentType.Code;

                return newControlSystemComponentType;
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:42,代码来源:CmsWebService.ControlModule.cs

示例7: DelArticle

 /// <summary>
 /// 删除文章
 /// </summary>
 /// <param name="varticle"></param>
 public void DelArticle(cms_varticle varticle)
 {
     using (CmsEntities entity = new CmsEntities())
     {
         var query = entity.cms_varticle.FirstOrDefault(m => m.id == varticle.id);
         if (query != null)
         {
             entity.cms_varticle.DeleteObject(query);
             entity.SaveChanges();
         }
     }
 }
开发者ID:91mvc,项目名称:YQCMS,代码行数:16,代码来源:ArticleServiceImpl.cs

示例8: AddSupervisorsToApprovals

        public void AddSupervisorsToApprovals()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                using (CmsEntities cee = new CmsEntities(120, mConnectCMS))
                {
                    var supervisorCategory = (from x in cee.IssueCategories where x.Code == "SUPERVISOR" select x).FirstOrDefault();
                    var pcsAdminUser = (from x in cee.Users where x.UserName == "pcsadmin" select x).FirstOrDefault();

                    var issues = (from x in cee.Issues orderby x.Id select x).ToList();

                    foreach (var issue in issues)
                    {
                        Console.Out.WriteLine("Processing issue {0}", issue.Id);

                        Issue issue1 = issue;
                        var hasAnyApprovalsChecked = (from x in cee.IssueApprovals
                                              where x.IssueId == issue1.Id
                                                    && x.IssueCategoryId != supervisorCategory.Id
                                                    && x.Approved
                                              select x).Any();

                        var hasSupervisor = (from x in cee.IssueApprovals
                                             where x.IssueId == issue1.Id
                                             && x.IssueCategoryId == supervisorCategory.Id
                                             select x).FirstOrDefault();

                        if (hasSupervisor == null && hasAnyApprovalsChecked)
                        {
                            var newIssueApproval = new IssueApproval
                                {
                                    IssueId = issue.Id,
                                    IssueCategoryId = supervisorCategory.Id,
                                    Approved = true,
                                    Approver = pcsAdminUser,
                                    Date = DateTime.Now
                                };

                            cee.IssueApprovals.Add(newIssueApproval);
                            Console.Out.WriteLine("Added Supervisor for IssueApproval on issue {0}", issue.Id);

                        }
                    }

                    cee.SaveChanges();

                    transaction.Complete();

                    Console.Out.WriteLine("Transaction Complete");
                    Console.ReadLine();
                }
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:53,代码来源:FixCategoriesDuplicates.cs

示例9: AddElectricalComponentType

        public ElectricalEquipmentComponentType AddElectricalComponentType(ElectricalEquipmentComponentType electricalEquipmentComponentType)
        {
            ElectricalEquipmentComponentType newMect = new ElectricalEquipmentComponentType();

            using (CmsEntities cee = new CmsEntities())
            {
                //Check if this component type already exist
                ElectricalEquipmentComponentType originalMect = (from x in cee.ElectricalEquipmentComponentTypes
                                                                 where x.Id == electricalEquipmentComponentType.Id
                                                                 select x).FirstOrDefault();

                if (originalMect != null)
                {
                    //Edit the Component Type
                    originalMect.Name = electricalEquipmentComponentType.Name;
                    originalMect.Description = electricalEquipmentComponentType.Description;
                    //pct.Code = mect.Code;
                    cee.SaveChanges();
                }
                else
                {
                    //Add new Component Type
                    originalMect = new ElectricalEquipmentComponentType();
                    originalMect.Name = electricalEquipmentComponentType.Name;
                    originalMect.Description = electricalEquipmentComponentType.Description;
                    originalMect.Code = electricalEquipmentComponentType.Name.Replace(" ", "");
                    originalMect.IsActive = true;

                    cee.ElectricalEquipmentComponentTypes.Add(originalMect);
                    //cee.AddToPipeComponentTypes(pct);
                    cee.SaveChanges();
                }

                newMect.Id = originalMect.Id;
                newMect.Name = originalMect.Name;
                newMect.Description = originalMect.Description;

                return newMect;
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:40,代码来源:CmsWebService.Electrical.cs

示例10: AddIssueTypeClassification

        public IssueTypeClassification AddIssueTypeClassification(int issueClassificationId, int issueTypeId)
        {
            using (var cee = new CmsEntities())
            {
                var issueTypeClassification = new IssueTypeClassification();

                issueTypeClassification.IssueClassificationId = issueClassificationId;
                issueTypeClassification.IssueTypeId = issueTypeId;

                cee.IssueTypeClassifications.Add(issueTypeClassification);
                cee.SaveChanges();

                return issueTypeClassification;
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:15,代码来源:CmsWebService.Issue.cs

示例11: RunFix

        public void RunFix()
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                using (CmsEntities cee = new CmsEntities(120,mConnectCMS))
                {
                    var issues = (from x in cee.Issues.Include("IssueAssignedCategories") orderby x.Id select x).ToList();

                    foreach (var issue in issues)
                    {
                        Console.Out.WriteLine("Processing issue {0}", issue.Id);

                        foreach (var issueAssignedCategory in issue.IssueAssignedCategories)
                        {
                            var closeoutExist = (from x in cee.IssueCloseouts
                                                 where
                                                     x.IssueId == issue.Id &&
                                                     x.IssueCategoryId == issueAssignedCategory.IssueCategoryId
                                                 select x).FirstOrDefault();

                            if (closeoutExist == null)
                            {
                                //CloseOut Doesnt exist add one
                                var newCloseout = new IssueCloseout
                                                      {
                                                          IssueId = issue.Id,
                                                          IssueCategoryId = issueAssignedCategory.IssueCategoryId
                                                      };
                                cee.IssueCloseouts.Add(newCloseout);
                                Console.Out.WriteLine("Added new category '{0}' closeout to issue {1}",
                                    issueAssignedCategory.IssueCategoryId,issue.Id);
                            }

                        }
                    }

                    cee.SaveChanges();

                    transaction.Complete();

                    Console.Out.WriteLine("Transaction Complete");
                    Console.ReadLine();
                }
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:45,代码来源:FixIssueCloseouts.cs

示例12: SavePipeSpecialFeature

        public PipeSpecialFeature SavePipeSpecialFeature(PipeSpecialFeature pipeSpecialFeature)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                //Check if the pipe area exist
                var originalPipeSpecialFeature = (from x in cee.PipeSpecialFeatures where x.Id == pipeSpecialFeature.Id select x).FirstOrDefault();

                if (originalPipeSpecialFeature == null)
                {
                    //Add new Pipe Special Feature
                    pipeSpecialFeature.Pipes = null;
                    cee.PipeSpecialFeatures.Add(pipeSpecialFeature);
                }
                else
                {
                    //Update existing Pipe Special Feature
                    originalPipeSpecialFeature.Name = pipeSpecialFeature.Name;
                    originalPipeSpecialFeature.Description = pipeSpecialFeature.Description;
                }

                cee.SaveChanges();
            }
            return pipeSpecialFeature;
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:24,代码来源:CmsWebService.Pipe.cs

示例13: DeletePipeAddHistory

        private void DeletePipeAddHistory(Pipe pipe, int userId, Pipe originalPipe, CmsEntities cee)
        {
            IEnumerable<PipeComponent> componentsToBeDeleted = (from x in originalPipe.PipeComponents
                                                                where !pipe.PipeComponents.Any(x1 => x1.Id == x.Id)
                                                                select x);

            PipeRevisionHistory rh = new PipeRevisionHistory();

            string[] componentMessages = (from x in componentsToBeDeleted select "Name: " + x.Name + " Type: " + x.PipeComponentType.Name).ToArray();

            if (componentMessages.Length > 0)
            {
                string removedItems = string.Join(",", componentMessages);

                rh.Description = string.Format("Pipe Components were removed : {0}", removedItems);
                rh.PipeId = pipe.Id;
                rh.Date = DateTime.Now;
                rh.UserId = userId;
                rh.IsSystemMessage = true;

                var latestPrh = (from x in cee.PipeRevisionHistories
                                 where x.PipeId == pipe.Id
                                 select x.Revision).ToList();

                if (latestPrh.Count > 0)
                {
                    rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
                }
                else
                {
                    rh.Revision = VERSIONINCREMENT;
                }
                cee.PipeRevisionHistories.Add(rh);
            }
            cee.SaveChanges();

            foreach (var pipeComponent in componentsToBeDeleted)
            {
                DeletePipeComponent(pipeComponent);
            }
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:41,代码来源:CmsWebService.Pipe.cs

示例14: SavePipeProperty

        public PipeProperty SavePipeProperty(PipeProperty pipeProperty)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                PipeProperty original = (from x in cee.PipeProperties where x.Id == pipeProperty.Id select x).FirstOrDefault();

                if (original == null)
                {
                    cee.PipeProperties.Add(pipeProperty);
                }
                else
                {
                    cee.Entry(original).CurrentValues.SetValues(pipeProperty);
                }

                cee.SaveChanges();
            }
            return pipeProperty;
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:19,代码来源:CmsWebService.Pipe.cs

示例15: SavePipePropertyValues

        public bool SavePipePropertyValues(List<PipePropertyValue> pipeComponentPropertyValues)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                foreach (var pipeComponentPropertyValue in pipeComponentPropertyValues)
                {
                    var q = (from x in cee.PipePropertyValues
                             where x.Id == pipeComponentPropertyValue.Id
                             select x).FirstOrDefault();

                    if (q == null)
                    {
                        q = new PipePropertyValue
                            {
                                ComponentId = pipeComponentPropertyValue.ComponentId,
                                PipePropertyId = pipeComponentPropertyValue.PipePropertyId,
                                Value = pipeComponentPropertyValue.Value
                            };
                        cee.PipePropertyValues.Add(q);
                        //cee.AddToPipePropertyValues(q);
                    }
                    else
                    {
                        q.PipePropertyId = pipeComponentPropertyValue.PipePropertyId;
                        q.ComponentId = pipeComponentPropertyValue.ComponentId;
                        q.Value = pipeComponentPropertyValue.Value;
                    }
                    cee.SaveChanges();
                }
            }
            return true;
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:32,代码来源:CmsWebService.Pipe.cs


注:本文中的CmsEntities.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。