示例#1
0
        /// <summary>
        /// 创建Domain
        /// </summary>
        /// <param name="domain"></param>
        public bool Insert(Domain domain)
        {
            DBDomain dbModel = ConvertModelHelper.ToDBDomainModel(domain);

            APIDoc_WebDBContext context = new APIDoc_WebDBContext();
            var dbDomain = (from q in context.Domains
                            where q.DomainId == domain.Id.Value
                          select q).FirstOrDefault();

            if (dbDomain == null)
            {
                context.Domains.Add(dbModel);
                context.SaveChanges();
                return true;
            }
            else
                return false;
        }
示例#2
0
        /// <summary>
        /// 更新Domain
        /// </summary>
        /// <param name="domain"></param>
        public bool Update(Domain domain)
        {
            DBDomain dbModel = ConvertModelHelper.ToDBDomainModel(domain);
            if (dbModel == null) return false;
            APIDoc_WebDBContext context = new APIDoc_WebDBContext();
            var dbDomain = (from q in context.Domains
                            where q.DomainId == domain.Id.Value
                            select q).FirstOrDefault();

            if (dbDomain == null)
            {
                context.Domains.Add(dbModel);

            }
            else
            {
                dbDomain.Title = dbModel.Title;
                dbDomain.Description = dbModel.Description;
                dbDomain.RootUrl = dbModel.RootUrl;
            }
            context.SaveChanges();
            return true;
        }
示例#3
0
        public static DBDomain ToDBDomainModel(Domain model)
        {
            if (model == null) return null;

            return new DBDomain
            {
                DomainId= model.Id.Value,
                Title = model.Title,
                Description = model.Description,
                RootUrl = model.RootUrl
            };
        }