Exemplo n.º 1
0
        /// <summary>
        /// Add Or Update User Detail In Database.
        /// </summary>
        /// <param name="objUserModel"></param>
        /// <returns></returns>
        public int AddEditUser(UserModel objUserModel)
        {
            System.Collections.ObjectModel.Collection <DBParameters> parameters = new System.Collections.ObjectModel.Collection <DBParameters>();

            if (objUserModel.UserId > 0)
            {
                parameters.Add(new DBParameters()
                {
                    Name = "@is_active", Value = objUserModel.Is_Active, DBType = DbType.Boolean
                });

                parameters.Add(new DBParameters()
                {
                    Name = "@user_id", Value = objUserModel.UserId, DBType = DbType.Int32
                });
                if (objUserModel.Role_Id > 0) /*only pass role in edit user*/
                {
                    parameters.Add(new DBParameters()
                    {
                        Name = "@role_id", Value = objUserModel.Role_Id, DBType = DbType.Int32
                    });
                }
            }

            if (!string.IsNullOrEmpty(objUserModel.Profile_Picture))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "@profile_picture", Value = Convert.FromBase64String(objUserModel.Profile_Picture.Split(',')[1]), DBType = DbType.Binary
                });
            }

            if (!string.IsNullOrEmpty(objUserModel.Document))
            {
                var documentContent = objUserModel.Document.Split(',');
                parameters.Add(new DBParameters()
                {
                    Name = "@document_name", Value = objUserModel.Document_Name, DBType = DbType.AnsiString
                });
                parameters.Add(new DBParameters()
                {
                    Name = "@document_detail", Value = documentContent[0] + ",", DBType = DbType.AnsiString
                });
                parameters.Add(new DBParameters()
                {
                    Name = "@document", Value = Convert.FromBase64String(documentContent[1]), DBType = DbType.Binary
                });
            }

            parameters.Add(new DBParameters()
            {
                Name = "@email", Value = objUserModel.Email, DBType = DbType.String
            });
            parameters.Add(new DBParameters()
            {
                Name = "@first_name", Value = objUserModel.First_name, DBType = DbType.AnsiString
            });
            parameters.Add(new DBParameters()
            {
                Name = "@last_name", Value = objUserModel.Last_name, DBType = DbType.AnsiString
            });
            parameters.Add(new DBParameters()
            {
                Name = "@mobile_number", Value = objUserModel.Mobile_number, DBType = DbType.AnsiString
            });
            parameters.Add(new DBParameters()
            {
                Name = "@education_id", Value = objUserModel.Education_Id, DBType = DbType.Int32
            });
            parameters.Add(new DBParameters()
            {
                Name = "@salary", Value = objUserModel.Salary, DBType = DbType.Decimal
            });
            parameters.Add(new DBParameters()
            {
                Name = "@birth_date", Value = objUserModel.BirthDay, DBType = DbType.Date
            });
            parameters.Add(new DBParameters()
            {
                Name = "@is_married", Value = objUserModel.Is_Married, DBType = DbType.Boolean
            });
            if (!string.IsNullOrEmpty(objUserModel.Token))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "@token", Value = objUserModel.Token, DBType = DbType.String
                });
            }

            if (!string.IsNullOrEmpty(objUserModel.Address))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "@address", Value = objUserModel.Address, DBType = DbType.AnsiString
                });
            }

            if (!string.IsNullOrEmpty(objUserModel.Blog))
            {
                parameters.Add(new DBParameters()
                {
                    Name = "@blog", Value = objUserModel.Blog, DBType = DbType.AnsiString
                });
            }

            parameters.Add(new DBParameters()
            {
                Name = "@created_by", Value = objUserModel.Updated_by, DBType = DbType.Int32
            });
            return(Convert.ToInt32(this.ExecuteProcedure("dbo.user_add_edit", ExecuteType.ExecuteScalar, parameters)));
        }