public ActionResult Edit(Guid? uid)
        {
            //check if user is logged in and authorized
            if (CurrentUser == null || !CurrentUser.Role.IsSystem)
            {
                return RedirectToAction("", "Home");
            }

            if (!uid.HasValue)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            CustomSecurity.User u = new CustomSecurity.User(ConfigurationManager.ConnectionStrings["SystemDS"].ToString(), new Guid(uid.ToString()));
            if (u == null)
            {
                HttpNotFound();
            }

            //create dropdown, this is accomplished by making the datatable IEnumerable
            var dt = CustomSecurity.Role.ToList(ConfigurationManager.ConnectionStrings["SystemDS"].ToString());
            ViewBag.Roles = new SelectList(dt, "RoleID", "Name", u.Role.RoleID.ToString());

            ViewBag.Lanaguages = new SelectList(Globalization.Language.ToList(ConfigurationManager.ConnectionStrings["SystemDS"].ToString())
                , "Code", "Name_EN", u.Demographics.Lanaguage);

            return View(convertToModel(u));
        }
        public ActionResult Edit(democode.mvc.Models.UserModels u, FormCollection form)
        {
            //create dropdown, this is accomplished by making the datatable IEnumerable
            var dt = CustomSecurity.Role.ToList(ConfigurationManager.ConnectionStrings["SystemDS"].ToString());
            ViewBag.Roles = new SelectList(dt, "RoleID", "Name", u.Role.RoleID.ToString());

            ViewBag.Lanaguages = new SelectList(Globalization.Language.ToList(ConfigurationManager.ConnectionStrings["SystemDS"].ToString())
                , "Code", "Name_EN", u.Demographics.Lanaguage);

            //any modification to the form inline will result in a false statement
            if (ModelState.IsValid)
            {
                CustomSecurity.User user = new CustomSecurity.User(ConfigurationManager.ConnectionStrings["SystemDS"].ToString(), u.UID);

                if (user == null)
                {
                    ViewBag.Message = "User dose not exist";
                    return View();
                }

                //get selected values from dropdowns
                var roleid = form["Roles"];

                user.UserName = u.Username;

                if (u.Demographics != null)
                {
                    user.Demographics.FirstName = u.Demographics.FirstName.Trim();
                    user.Demographics.LastName = u.Demographics.LastName.Trim();
                    user.Demographics.DateOfBirth = u.Demographics.DateOfBirth;
                    user.Demographics.Gender = u.Demographics.Gender;
                    user.Demographics.Lanaguage = u.Demographics.Lanaguage;
                    user.Demographics.Country = u.Demographics.Country;
                    user.Demographics.PostalCode = u.Demographics.PostalCode;
                    user.Demographics.PhoneMobile = u.Demographics.PhoneMobile;
                }

                //EditUser.Role
                //if the selected role is not the same as the one currently assigned
                //then remove and add new role; otherwise do nothing
                if (roleid != user.Role.RoleID.ToString())
                {
                    if (CustomSecurity.Role.RemoveUserFromRole(ConfigurationManager.ConnectionStrings["SystemDS"].ToString(), user.UID,
                        user.Role.RoleID))
                    {
                        CustomSecurity.Role.AddUserToRole(ConfigurationManager.ConnectionStrings["SystemDS"].ToString(), user.UID,
                           new Guid(roleid));
                    }
                    else
                    {
                        ViewBag.Message = CustomSecurity.Role.GetLastError.Message;
                    }
                }

                if (u.Membership != null)
                {
                    //EditUser.Membership
                    user.Membership.Email = u.Membership.Email;
                    //only update users password if one was entered
                    if (!string.IsNullOrEmpty(u.Membership.Password))
                    {
                        string salt;
                        user.Membership.Password = CustomSecurity.PasswordHash.CreateHash(u.Membership.Password, out salt);
                        user.Membership.PasswordSalt = salt;
                        user.Membership.PasswordFormat = (Int16)CustomSecurity.PasswordFormat.PBKDF2;
                    }
                }

                user.Update(ConfigurationManager.ConnectionStrings["SystemDS"].ToString());

                ViewBag.Message = "user updated";

                return RedirectToAction("");
            }
            else
            {
                ViewBag.Message = "Invalid Post";
                return View(u);
            }
        }
        private CustomSecurity.User convertFromModel(democode.mvc.Models.UserModels data)
        {
            CustomSecurity.User x = new CustomSecurity.User();
            try
            {
                x.UID = data.UID;
                x.APPID = data.AppID;
                x.UserName = data.Username;
                x.IsAnonymous = data.IsAnonymous;
                x.LastActivityDate = data.LastActivityDate;
                //x.TimeStamp = data._timestamp;

                x.Demographics = data.Demographics;
                x.Membership = data.Membership;
                x.Role = data.Role;

                return x;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Return Serialized String version of [data] Object
        /// </summary>
        /// <param name="data">as User</param>
        /// <returns></returns>
        /// <remarks></remarks>
        private static string XMLSerializeToString(User data)
        {
            try
            {
                XmlSerializer xmlSer = new XmlSerializer(typeof(User));
                MemoryStream ms = new MemoryStream();
                StreamReader strReader = default(StreamReader);
                string output = null;

                xmlSer.Serialize(ms, data);
                ms.Position = 0;
                strReader = new StreamReader(ms);
                output = strReader.ReadToEnd();
                return output;
            }
            catch (Exception ex)
            {
                _LastError = ex;
                return null;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Set MyBase to values of [data]
        /// </summary>
        /// <param name="data">as user</param>
        /// <returns></returns>
        internal Boolean SetBase(User data)
        {
            try
            {
                _uid = data.UID;
                _appid = data.APPID;
                _username = data.UserName;
                _isAnonymous = data.IsAnonymous;
                _lastActivityDate = data.LastActivityDate;
                _timestamp = data._timestamp;

                return true;
            }
            catch (Exception ex)
            {
                _LastError = ex;
                throw ex;
            }
        }
Beispiel #6
0
 public int CompareTo(User other)
 {
     return _uid.CompareTo(other.UID);
 }