コード例 #1
0
 public IQueryable<HtmlContent> Get()
 {
     using (var db = new Dbml.DataClassesDataContext(ConnectionString))
     {
         // TODO: This is a somewhat strange usage, and should be looked into; if we don't convert to a list
         // first, then we get an exception as the DataContext has been disposed by the time the IQueryable is
         // materialized "later on"; however, if we do convert to a list, this is an extra processing hit
         return db.HtmlContents.Select(x => Mapper.Map<Dbml.HtmlContent, HtmlContent>(x))
             .ToList()
             .AsQueryable();
     }
 }
コード例 #2
0
        public UserProfile Save(UserProfile entity)
        {
            using (Dbml.DataClassesDataContext db = new Dbml.DataClassesDataContext(this.ConnectionString))
            {
                Dbml.UserProfile dbItem = db.UserProfiles.Where(x => x.Id == entity.Id).SingleOrDefault();
                bool isNew = false;
                if (dbItem == null)
                {
                    dbItem = new Dbml.UserProfile();
                    isNew = true;
                }
                else
                {
                    //remove them for refresh
                    //wish there was a better way to do this but...
                    db.Application_UserProfiles.DeleteAllOnSubmit
                    (
                        db.Application_UserProfiles.Where(x => x.UserProfileId ==  entity.Id)
                    );
                }
                foreach( Ent.Application a in entity.Applications)
                {
                    Dbml.Application_UserProfile dbAppUser = new Dbml.Application_UserProfile();
                    dbAppUser.UserProfileId = entity.Id;
                    dbAppUser.ApplicationId = a.Id;
                    dbItem.Application_UserProfiles.Add(dbAppUser);
                }
                dbItem.Name = entity.Name;
                dbItem.Email = entity.Email;
                dbItem.LastSignInDate = entity.LastSignInDate;
                dbItem.OpenIdId = entity.OpenIdId;
                dbItem.RegisterDate = entity.RegisterDate;
                dbItem.UserName = entity.UserName;
                dbItem.ModifiedBy = entity.ModifiedBy;
                dbItem.ModifiedDate = entity.ModifiedDate;
                dbItem.CreatedDate = entity.CreatedDate;
                dbItem.CreatedBy = entity.CreatedBy;

                if (isNew)
                {
                    db.UserProfiles.InsertOnSubmit(dbItem);
                }
                db.SubmitChanges();

                entity.Id = dbItem.Id;
                return entity;
            }
        }
コード例 #3
0
        public HtmlContent Save(HtmlContent entity)
        {
            using (var db = new Dbml.DataClassesDataContext(ConnectionString))
            {
                #region Bulk Test...

                ////File.AppendAllText("WhenItStarted.txt", DateTime.Now.ToString());

                //for (int i = 2; i <= 1000; i++)
                //{

                //    item.Id = -2;

                //    Dbml.HtmlContent dbItem = db.HtmlContents.Where(x => x.Id == item.Id).SingleOrDefault();
                //    bool isNew = false;
                //    if (dbItem == null)
                //    {
                //        dbItem = new Dbml.HtmlContent();
                //        isNew = true;
                //    }

                //    dbItem.Name = item.Name;
                //    dbItem.ContentData = item.ContentData;
                //    dbItem.ActiveDate = item.ActiveDate;
                //    dbItem.ExpireDate = item.ExpireDate;
                //    dbItem.ModifiedBy = item.ModifiedBy;
                //    dbItem.ModifiedDate = item.ModifiedDate;

                //    if (isNew)
                //    {
                //        db.HtmlContents.InsertOnSubmit(dbItem);
                //    }
                //    try
                //    {
                //        db.SubmitChanges();
                //    }
                //    catch (Exception e)
                //    {
                //        string s = e.Message;
                //        throw;
                //    }
                //    item.Id = dbItem.Id;
                //}

                ////File.AppendAllText("WhenItStarted.txt", DateTime.Now.ToString());

                #endregion

                Dbml.HtmlContent dbItem = db.HtmlContents.Where(x => x.Id == entity.Id).SingleOrDefault();
                bool isNew = false;

                if (dbItem == null)
                {
                    dbItem = new Dbml.HtmlContent();
                    isNew = true;
                }

                // Map from Domain => DataContext
                Mapper.Map(entity, dbItem);

                if (isNew)
                {
                    db.HtmlContents.InsertOnSubmit(dbItem);
                }

                db.SubmitChanges();

                entity.Id = dbItem.Id;

                return entity;
            }
        }
コード例 #4
0
 public SqlUserProfileRepository(Dbml.DataClassesDataContext dataContext)
 {
     _db = dataContext;
 }
コード例 #5
0
 public SqlApplicationRepository(Dbml.DataClassesDataContext dataContext)
 {
     _db = dataContext;
 }