コード例 #1
0
ファイル: UserInfoRepo.cs プロジェクト: Risha09/ATP2.BDAID
        public Result <UserInfo> Save(UserInfo userinfo)
        {
            var result = new Result <UserInfo>();

            try
            {
                var objtosave = DbContext.UserInfos.FirstOrDefault(u => u.ID == userinfo.ID);
                if (objtosave == null)
                {
                    objtosave = new UserInfo();
                    DbContext.UserInfos.Add(objtosave);
                }
                objtosave.Name       = userinfo.Name;
                objtosave.Username   = userinfo.Username;
                objtosave.UsertypeID = userinfo.UsertypeID;
                objtosave.Email      = userinfo.Email;
                objtosave.Password   = userinfo.Password;
                objtosave.Gender     = userinfo.Gender;
                objtosave.Age        = userinfo.Age;
                objtosave.Contact    = userinfo.Contact;

                if (!IsValid(objtosave, result))
                {
                    return(result);
                }
                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
コード例 #2
0
ファイル: UserInfoRepo.cs プロジェクト: Risha09/ATP2.BDAID
 private bool IsValid(UserInfo obj, Result <UserInfo> result)
 {
     if (!ValidationHelper.IsStringValid(obj.Name))
     {
         result.HasError = true;
         result.Message  = "Invalid Name";
         return(false);
     }
     if (!ValidationHelper.IsStringValid(obj.Username))
     {
         result.HasError = true;
         result.Message  = "Invalid UserName";
         return(false);
     }
     if (!ValidationHelper.IsStringValid(obj.Password) || obj.Password.Length < 8)
     {
         result.HasError = true;
         result.Message  = "Invalid Password";
         return(false);
     }
     if (DbContext.UserInfos.Any(u => u.Username == obj.Username && u.ID != obj.ID))
     {
         result.HasError = true;
         result.Message  = "UserName already exists";
         return(false);
     }
     if (DbContext.UserInfos.Any(u => u.Email == obj.Email && u.ID != obj.ID))
     {
         result.HasError = true;
         result.Message  = "Invalid Email";
         return(false);
     }
     return(true);
 }
コード例 #3
0
ファイル: UserInfoService.cs プロジェクト: Risha09/ATP2.BDAID
        private bool IsValid(UserInfo obj, Result <UserInfo> result)
        {
            if (!ValidationHelper.IsStringValid(obj.Name))
            {
                result.HasError = true;
                result.Message  = "Invalid Name";
                return(false);
            }

            if (!ValidationHelper.IsStringValid(obj.Email))
            {
                result.HasError = true;
                result.Message  = "Invalid Email";
                return(false);
            }

            if (!ValidationHelper.IsStringValid(obj.Password) || obj.Password.Length < 8)
            {
                result.HasError = true;
                result.Message  = "Invalid Password";
                return(false);
            }

            string query = "select * from UserInfo where Email='" + obj.Email + "' and ID!=" + obj.ID;
            var    dt    = DataAccess.GetDataTable(query);

            if (dt != null && dt.Rows.Count > 0)
            {
                result.HasError = true;
                result.Message  = "Email Exists";
                return(false);
            }
            return(true);
        }
コード例 #4
0
ファイル: UserInfoService.cs プロジェクト: Risha09/ATP2.BDAID
        public Result <UserInfo> Login2(string email)
        {
            var result = new Result <UserInfo>();

            try
            {
                string query = "select * from UserInfo where Email='" + email + "'";
                var    dt    = DataAccess.GetDataTable(query);

                if (dt == null || dt.Rows.Count == 0)
                {
                    var userInfo = new UserInfo()
                    {
                        ID = 0, Email = email, Name = email, Password = "******", StatusID = (int)EnumCollection.UserStatusEnum.Active, UserTypeID = (int)EnumCollection.UserTypeEnum.NonRegisteredUser
                    };

                    return(this.Save(userInfo));
                }

                result.Data = ConvertToEntity(dt.Rows[0]);
                if (result.Data.UserTypeID != (int)EnumCollection.UserTypeEnum.NonRegisteredUser)
                {
                    result.HasError = true;
                    result.Message  = "Only Non-Registered User Can Use This Feature";
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
コード例 #5
0
ファイル: UserInfoService.cs プロジェクト: Risha09/ATP2.BDAID
 private UserInfo ConvertToEntity(DataRow row)
 {
     try
     {
         UserInfo u = new UserInfo();
         u.ID         = Int32.Parse(row["ID"].ToString());
         u.Name       = row["UName"].ToString();
         u.Email      = row["Email"].ToString();
         u.Password   = row["Password"].ToString();
         u.UserTypeID = Int32.Parse(row["UserTypeID"].ToString());
         u.StatusID   = Int32.Parse(row["StatusID"].ToString());
         return(u);
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #6
0
ファイル: UserInfoService.cs プロジェクト: Risha09/ATP2.BDAID
        public Result <UserInfo> Save(UserInfo userinfo)
        {
            var result = new Result <UserInfo>();

            try
            {
                string query = "select * from UserInfo where ID=" + userinfo.ID;
                var    dt    = DataAccess.GetDataTable(query);

                if (dt == null || dt.Rows.Count == 0)
                {
                    userinfo.ID = GetID();
                    query       = "insert into UserInfo values(" + userinfo.ID + ",'" + userinfo.Name + "','" + userinfo.Email + "','" + userinfo.Password + "'," + userinfo.UserTypeID + "," + userinfo.StatusID + ")";
                }
                else
                {
                    query =
                        "update UserInfo set UName='" + userinfo.Name + "',Email='" + userinfo.Email + "',Password="******",UsertypeID=" + userinfo.UserTypeID + ",StatusID=" + userinfo.StatusID + " where ID=" +
                        userinfo.ID;
                }

                if (!IsValid(userinfo, result))
                {
                    return(result);
                }

                result.HasError = DataAccess.ExecuteQuery(query) <= 0;

                if (result.HasError)
                {
                    result.Message = "Something Went Wrong";
                }
                else
                {
                    result.Data = userinfo;
                }
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message  = ex.Message;
            }
            return(result);
        }
コード例 #7
0
ファイル: UserInfoService.cs プロジェクト: Risha09/ATP2.BDAID
        public List <UserInfo> GetAllByTypeID(int typeID)
        {
            var result = new List <UserInfo>();

            try
            {
                string query = "select * from UserInfo where USERTYPEID=" + typeID;
                var    dt    = DataAccess.GetDataTable(query);

                if (dt != null && dt.Rows.Count != 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        UserInfo u = ConvertToEntity(dt.Rows[i]);
                        result.Add(u);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(result);
        }