예제 #1
0
 //CREATE
 public bool CreateReply(ReplyCreate model)
 {
     using (var db = new ApplicationDbContext())
     {
         if (db.Profiles.SingleOrDefault(p => p.UserID == _userId) == null)
         {
             var svc = new ProfileService(_userId);
             svc.CreateProfile(_userId);
         }
         var entity = new Reply()
         {
             UserID     = _userId,
             Body       = model.Body,
             TimePosted = DateTimeOffset.Now,
             PostID     = model.PostID,
         };
         db.Replies.Add(entity);
         return(db.SaveChanges() == 1);
     }
 }
예제 #2
0
        //CREATE
        public bool CreatePost(PostCreate model)
        {
            using (var db = new ApplicationDbContext())
            {
                var userProfile = db.Profiles.SingleOrDefault(p => p.UserID == _userId);
                if (userProfile == null)
                {
                    var svc = new ProfileService(_userId);
                    svc.CreateProfile(_userId);
                }
                var entity = new Post()
                {
                    UserID     = _userId,
                    Title      = model.Title,
                    Body       = model.Body,
                    TimePosted = DateTimeOffset.Now,
                    Profile    = db.Profiles.Single(p => p.UserID == _userId)
                };


                db.Posts.Add(entity);
                return(db.SaveChanges() == 1);
            }
        }