コード例 #1
0
 /// <summary>
 /// 使用使用者模型物件,新增使用者
 /// </summary>
 /// <param name="userModel">使用者模型物件</param>
 /// <returns>新增結果</returns>
 public PoResult CreateUser(UserCreateVm userModel)
 {
     try
     {
         var isEmailExit = this.Database.Users.Any(o => o.Email == userModel.Email);
         if (isEmailExit)
         {
             return(PoResult.Fail("電子郵件重複"));
         }
         var isUserNameExit = this.Database.Users.Any(o => o.UserName == userModel.UserName);
         if (isUserNameExit)
         {
             return(PoResult.Fail("使用者名稱重複重複"));
         }
         this.Database.Users.Add(new User
         {
             Id               = Ci.Sequential.Guid.Create(),
             Email            = userModel.Email,
             UserName         = userModel.UserName,
             Password         = PasswordHash(userModel.Password),
             CreateTime       = DateTime.Now,
             HeadPortraitPath = userModel.ImagePath
         });
         this.Database.SaveChanges();
         return(PoResult.PoSuccess());
     }
     catch (Exception e)
     {
         return(PoResult.Exception(e));
     }
 }
コード例 #2
0
        /// <summary>
        /// 使用清單名稱、帳號,新增清單
        /// </summary>
        /// <param name="listName">清單名稱</param>
        /// <param name="account">帳號</param>
        /// <returns>新增結果</returns>
        public PoResult <ToDoList> CreateList(string listName, string account)
        {
            try
            {
                var user = this.Database.Users.FirstOrDefault(o => o.Account == account);
                if (user == null)
                {
                    return(PoResult <ToDoList> .DbNotFound());
                }

                var toDoList = this.Database.ToDoLists.Add(new ToDoList
                {
                    Id     = Guid.Create(),
                    Name   = listName,
                    UserId = user.Id,
                    Sort   = user.ToDoLists.Count
                });

                this.Database.SaveChanges();
                return(PoResult <ToDoList> .PoSuccess(toDoList));
            }
            catch (Exception e)
            {
                return(PoResult <ToDoList> .Exception(e));
            }
        }
コード例 #3
0
 /// <summary>
 /// 使用帳號,取得使用者物件
 /// </summary>
 /// <param name="account">帳號</param>
 /// <returns>使用者物件</returns>
 public PoResult <User> GetUser(string account)
 {
     try
     {
         var user = this.Database.Users.FirstOrDefault(o => o.Account == account);
         return(user == null ? PoResult <User> .DbNotFound() : PoResult <User> .PoSuccess(user));
     }
     catch (Exception e)
     {
         return(PoResult <User> .Exception(e));
     }
 }
コード例 #4
0
 /// <summary>
 /// 使用信箱,取得使用者
 /// </summary>
 /// <param name="email">使用者的信箱</param>
 /// <returns>取得結果</returns>
 public PoResult <User> GetUserByEmail(string email)
 {
     try
     {
         var user = this.Database.Users.FirstOrDefault(o => o.Email == email);
         return(user == null ? PoResult <User> .DbNotFound() : PoResult <User> .PoSuccess(user));
     }
     catch (Exception e)
     {
         return(PoResult <User> .Exception(e));
     }
 }
コード例 #5
0
 /// <summary>
 /// 使用Id,取得使用者
 /// </summary>
 /// <param name="userId">使用者Id</param>
 /// <returns>取得結果</returns>
 public PoResult <User> GetUser(Guid userId)
 {
     try
     {
         var user = this.Database.Users.Find(userId);
         return(user == null ? PoResult <User> .DbNotFound() : PoResult <User> .PoSuccess(user));
     }
     catch (Exception e)
     {
         return(PoResult <User> .Exception(e));
     }
 }
コード例 #6
0
 /// <summary>
 /// 使用使用者帳號,取得使用者的待辦清單
 /// </summary>
 /// <param name="userAccount">使用者帳號</param>
 /// <returns>使用者的待辦清單</returns>
 public PoResult <List <ToDoList> > GetUserToDoLists(string userAccount)
 {
     try
     {
         var toDoLists = this.Database.ToDoLists.Where(o => o.User.Account == userAccount).Include(o => o.Folder).OrderBy(o => o.Sort).ToList();
         return(PoResult <List <ToDoList> > .PoSuccess(toDoLists));
     }
     catch (Exception e)
     {
         return(PoResult <List <ToDoList> > .Exception(e));
     }
 }
コード例 #7
0
 /// <summary>
 /// 使用帳號、密碼,驗證使用者
 /// </summary>
 /// <param name="account">帳號</param>
 /// <param name="password">密碼</param>
 /// <returns>驗證結果</returns>
 public PoResult VerifyUser(string account, string password)
 {
     try
     {
         var userResult = this.GetUser(account);
         if (!userResult.Success)
         {
             return(PoResult.Fail("帳號不存在"));
         }
         return(userResult.Data.Password == PasswordHash(password) ? PoResult.PoSuccess() : PoResult.Fail("密碼錯誤"));
     }
     catch (Exception e)
     {
         return(PoResult.Exception(e));
     }
 }
コード例 #8
0
        /// <summary>
        /// 使用待辦清單Id陣列、使用者帳號,更新待辦清單的排序
        /// </summary>
        /// <param name="listIds">待辦清單Id陣列</param>
        /// <param name="userAccount">使用者帳號</param>
        /// <returns>更新結果</returns>
        public PoResult UpdateListSort(System.Guid[] listIds, string userAccount)
        {
            try
            {
                var index = 0;
                foreach (var listId in listIds)
                {
                    var toDoList = this.Database.ToDoLists.FirstOrDefault(o => o.Id == listId && o.User.Account == userAccount);
                    if (toDoList == null)
                    {
                        return(PoResult.DbNotFound());
                    }
                    toDoList.Sort = index++;
                }

                this.Database.SaveChanges();
                return(PoResult.PoSuccess());
            }
            catch (Exception e)
            {
                return(PoResult.Exception(e));
            }
        }
コード例 #9
0
 /// <summary>
 /// 使用使用者物件,新增使用者
 /// </summary>
 /// <param name="userModel">使用者物件</param>
 /// <returns>新增結果</returns>
 public PoResult CreateUser(UserCreateVm userModel)
 {
     try
     {
         var isUserExist = this.Database.Users.Any(o => o.Account == userModel.Account);
         if (isUserExist)
         {
             return(PoResult.Fail("帳號重複"));
         }
         this.Database.Users.Add(new User
         {
             Id         = Ci.Sequential.Guid.Create(),
             Account    = userModel.Account,
             Password   = PasswordHash(userModel.Password),
             CreateTime = DateTime.Now
         });
         this.Database.SaveChanges();
         return(PoResult.PoSuccess());
     }
     catch (Exception e)
     {
         return(PoResult.Exception(e));
     }
 }