Exemplo n.º 1
0
        /// <summary>
        /// Model类Basic_User_Info转化为数据库表Basic_User
        /// </summary>
        /// <param name="info">要转化的Model类Basic_User_Info</param>
        /// <returns>转化后的数据库表Basic_User</returns>
        private Basic_User ToDatabase(Basic_User_Info info)
        {
            Basic_User user = new Basic_User();

            user.Id           = info.Id;
            user.Account      = info.Account;
            user.Password     = info.Password;
            user.Avatar       = info.Avatar;
            user.Cover        = info.Cover;
            user.Limit        = info.Limit;
            user.Email        = info.Email;
            user.Phone_Number = info.Phone_Number;

            return(user);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 数据库表Basic_User转化为Model类Basic_User_Info
        /// </summary>
        /// <param name="user">要转化的Model类Basic_User</param>
        /// <returns>转化后的数据库表Basic_User_Info</returns>
        private Basic_User_Info ToModel(Basic_User user)
        {
            Basic_User_Info info = new Basic_User_Info();

            info.Id           = user.Id;
            info.Account      = user.Account;
            info.Password     = user.Password;
            info.Avatar       = user.Avatar;
            info.Cover        = user.Cover;
            info.Limit        = (bool)user.Limit;
            info.Email        = user.Email;
            info.Phone_Number = user.Phone_Number;

            return(info);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新Basic_User中的一条数据
        /// </summary>
        /// <param name="id">用户id</param>
        /// <param name="changes">要更新的值,可以包括多个键值对</param>
        /// <returns>是否更新成功</returns>
        public bool Update(Guid id, Dictionary <string, string> changes)
        {
            using (MovieResShareEntities database = new MovieResShareEntities())
            {
                try
                {
                    Basic_User user = database.Basic_User.FirstOrDefault(p => p.Id == id);

                    foreach (var item in changes)
                    {
                        switch (item.Key)
                        {
                        case "password":
                            user.Password = item.Value;
                            break;

                        case "avatar":
                            user.Avatar = item.Value;
                            break;

                        case "cover":
                            user.Cover = item.Value;
                            break;

                        case "limit":
                            user.Limit = bool.Parse(item.Value);
                            break;

                        case "email":
                            user.Email = item.Value;
                            break;

                        case "phone":
                            user.Phone_Number = item.Value;
                            break;

                        default: break;
                        }
                    }
                    database.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 从Basic_User中删除一条数据
 /// </summary>
 /// <param name="id">用户id</param>
 /// <returns>是否删除成功</returns>
 public bool Delete(Guid id)
 {
     using (MovieResShareEntities database = new MovieResShareEntities())
     {
         try
         {
             Basic_User user = database.Basic_User.FirstOrDefault(p => p.Id == id);
             database.Basic_User.Remove(user);
             database.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }