Ejemplo n.º 1
0
        public ActionResult registerUser(string firstName,
                                         string lastName,
                                         string nickName,
                                         string dateOfBirth,
                                         string role,
                                         string userName,
                                         string password)
        {
            int valid = 1;
            var Jcon = new JsonContainer();
            var objUserAccountHelper = new UserAccountHelper();

            if (objUserAccountHelper.VerifyUserName(userName))
            {
                Jcon.Result = -1;
                return Json(Jcon);
            }

            DateTime date;

            if (!DateTime.TryParse(dateOfBirth, out date))
            {
                Jcon.Result = 0;
                return Json(Jcon);
            }

            var userDetails = new UserAccount
            {
                firstName = firstName,
                lastName = lastName,
                nickName = nickName,
                dateOfBirth = date,
                role = role,
                userName = userName,
                password = password
            };

            try
            {
                objUserAccountHelper.InsertUserDetails(userDetails);
            }
            catch (Exception ex)
            {
                valid = 0;
            }

            Jcon.Result = valid;
            return Json(Jcon);
        }
        public void InsertUserDetails(UserAccount userDetails)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                var cmd = new SqlCommand("insertUserDetails", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                //cmd.Parameters.Add("@firstName", SqlDbType.NVarChar).Value = userDetails.firstName;
                cmd.Parameters.Add(new SqlParameter("@firstName", userDetails.firstName));
                cmd.Parameters.Add(new SqlParameter("@lastName", userDetails.lastName));
                cmd.Parameters.Add(new SqlParameter("@nickName", userDetails.nickName));
                cmd.Parameters.Add(new SqlParameter("@dateOfBirth", userDetails.dateOfBirth));
                cmd.Parameters.Add(new SqlParameter("@role", userDetails.role));
                cmd.Parameters.Add(new SqlParameter("@userName", userDetails.userName));
                cmd.Parameters.Add(new SqlParameter("@password", Cryptography.CreateHash(userDetails.password)));
                cmd.Parameters.Add(new SqlParameter("@isActive", 'Y'));
                cmd.ExecuteNonQuery();

                conn.Close();
            }
        }
Ejemplo n.º 3
0
        public ActionResult updateUserDetails(string firstName,
                                        string lastName,
                                        string nickName,
                                        string dateOfBirth)
        {
            int valid = 1;
            var Jcon = new JsonContainer();
            var objUserAccountHelper = new UserAccountHelper();

            DateTime date;

            if (!DateTime.TryParse(dateOfBirth, out date))
            {
                Jcon.Result = 0;
                return Json(Jcon);
            }

            var userDetails = new UserAccount
            {
                userId = long.Parse(Session["userId"].ToString()),
                firstName = firstName,
                lastName = lastName,
                nickName = nickName,
                dateOfBirth = date
            };

            try
            {
                objUserAccountHelper.UpdateUserDetails(userDetails);
            }
            catch (Exception ex)
            {
                valid = 0;
            }

            Jcon.Result = valid;
            return Json(Jcon);
        }
        public void UpdateUserDetails(UserAccount userDetails)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                var cmd = new SqlCommand("updateUserDetails", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@userId", userDetails.userId));
                cmd.Parameters.Add(new SqlParameter("@firstName", userDetails.firstName));
                cmd.Parameters.Add(new SqlParameter("@lastName", userDetails.lastName));
                cmd.Parameters.Add(new SqlParameter("@nickName", userDetails.nickName));
                cmd.Parameters.Add(new SqlParameter("@dateOfBirth", userDetails.dateOfBirth));

                cmd.ExecuteNonQuery();

                conn.Close();
            }
        }