コード例 #1
0
 internal bool Create(Account account, string name, int initScore)
 {
     account.Password = account.Password.ToMd5();
     account.Code     = DateTime.Now.Ticks;
     using (IDbEntities db = DbInstance)
     {
         db.Account.Add(account);
         db.SaveChanges();
         if (account.UserId < 999)
         {
             return(false);
         }
         db.Profile.Add(new Profile
         {
             UserId    = account.UserId,
             Name      = name,
             ShowScore = initScore,
             Score     = initScore,
             DelScore  = 0,
             Status    = (int)RoleType.General,
             RegTime   = DateTime.Now,
             LoginTime = DateTime.Now,
             // MagicBox = ""
         });
         db.BasicInformation.Add(
             new BasicInformation
         {
             UserId = account.UserId,
             Name   = name
         });
         db.SaveChanges();
         return(true);
     }
 }
コード例 #2
0
 public void DeleteReply(long id, long userid)
 {
     using (IDbEntities db = DbInstance)
     {
         Reply obj = db.Reply.FirstOrDefault(c => c.Id == id && c.UserId == userid);
         db.Reply.Remove(obj);
         db.SaveChanges();
     }
 }
コード例 #3
0
 public Reply AddReply(Reply r)
 {
     r.AddTime = DateTime.Now;
     using (IDbEntities db = DbInstance)
     {
         db.Reply.Add(r);
         db.SaveChanges();
     }
     return(r);
 }
コード例 #4
0
        public void InitCreater()
        {
            using (IDbEntities db = DbInstance)
            {
                Profile p = db.Profile.FirstOrDefault();
                if (p == null)
                {
                    return;
                }

                var userrole = new UserRole
                {
                    RoleId = 1,
                    UserId = p.UserId
                };
                db.UserRole.Add(userrole);
                db.SaveChanges();
            }
        }
コード例 #5
0
        public void Add(Comment cmt, CommentType type)
        {
            cmt.AddTime = DateTime.Now;
            using (IDbEntities db = DbInstance)
            {
                db.Comment.Add(cmt);
                switch (type)
                {
                case CommentType.Note:
                    Note n = db.Note.FirstOrDefault(c => c.Id == cmt.ShowerId);
                    n.CommentCount++;
                    break;

                default:
                    break;
                }
                db.SaveChanges();
            }
        }
コード例 #6
0
        internal WebIdentity GeneralIdentity(String userName, String password, int logOnScore)
        {
            using (IDbEntities db = DbInstance)
            {
                long userId;
                long.TryParse(userName.Trim(), out userId);
                long userid = (from a in db.Account
                               where (a.UserName == userName || a.UserId == userId) &&
                               a.Password == password
                               select a.UserId).FirstOrDefault();
                if (userid <= 1000)
                {
                    return(null);
                }
                Profile       profile = db.Profile.FirstOrDefault(p => p.UserId == userid);
                List <string> roles   = (from ur in db.UserRole
                                         join ro in db.Roles on ur.RoleId equals ro.Id
                                         where ur.UserId == profile.UserId
                                         select ro.RoleName).ToList();
                //var retint = profile.Status;
                // if (retint <= 0) return null;
                if (profile.LoginTime.Date != DateTime.Now.Date)
                {
                    profile.Score     += logOnScore;
                    profile.ShowScore += logOnScore;
                    profile.LoginTime  = DateTime.Now;
                    db.SaveChanges();
                }
                return(new WebIdentity
                {
                    Name = profile.Name,
                    UserId = profile.UserId,
                    // Email= profile.
                    Roles = roles,
                    Status = profile.Status
                             //                    AuthenticationType = AccountType.Default.ToString()

                             //Status = retint,
                             //Applications = profile.Applications
                });
            }
        }
コード例 #7
0
 /// <summary>
 /// 删除回复
 /// </summary>
 /// <param name="id"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public bool Delete(long id, CommentType type)
 {
     using (IDbEntities db = DbInstance)
     {
         Comment com = db.Comment.FirstOrDefault(c => c.Id == id);
         if (null == com)
         {
             return(false);
         }
         com.IsDel = true;
         if (type == CommentType.Note)
         {
             Note n = db.Note.FirstOrDefault(c => c.Id == com.ShowerId && c.CommentCount > 0);
             if (null != n)
             {
                 n.CommentCount--;
             }
         }
         db.SaveChanges();
         return(true);
     }
 }