コード例 #1
0
        public static bool UpdateUserProfile(ProfileInfo profile, long userId, out string msg)
        {
            try
            {
                if (profile == null)
                {
                    msg = "Empty / Invalid Profile Object";
                    return(false);
                }
                if (userId < 1)
                {
                    msg = "Empty / Invalid Profile Object";
                    return(false);
                }
                var propertyInfos = typeof(ProfileInfo).GetProperties();
                if (!propertyInfos.Any())
                {
                    msg = "Invalid Profile Object";
                    return(false);
                }

                var user = PortalUser.GetRawUser(userId);
                if (user == null || user.UserId < 1)
                {
                    msg = "Unable to retrieve user detail information!";
                    return(false);
                }

                user.Sex          = (int)profile.Sex;
                user.FirstName    = profile.FirstName;
                user.Surname      = profile.LastName;
                user.MobileNumber = profile.MobileNo;


                var retId = PortalUser.UpdateUser(user, out msg);
                if (!retId)
                {
                    if (string.IsNullOrEmpty(msg))
                    {
                        msg = "Process Failed! Please try again later";
                    }
                    return(false);
                }

                msg = "";
                return(true);
            }
            catch (Exception ex)
            {
                msg = "Error: " + ex.Message;
                BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                return(false);
            }
        }
コード例 #2
0
        public ActionResult ModifyUser(string id, AuthPortalUser model)
        {
            try
            {
                long userId;
                Int64.TryParse(id, out userId);

                if (userId < 1)
                {
                    ViewBag.Error = "Invalid selection";
                    return(Redirect(Url.RouteUrl(new { action = "Index" })));
                }

                if (model == null)
                {
                    Session["Error"] = "Your session has expired! Please, re-login";
                    return(Redirect(Url.RouteUrl(new { action = "Index" })));
                }

                if (Session["_selectedPortalUser"] == null)
                {
                    Session["Error"] = "Your session has expired! Please, re-login";
                    return(Redirect(Url.RouteUrl(new { action = "Index" })));
                }

                var thisUser = Session["_selectedPortalUser"] as RegisteredUserReportObj;
                if (thisUser == null || thisUser.UserId < 1)
                {
                    Session["Error"] = "Your session has expired! Please, re-login";
                    return(Redirect(Url.RouteUrl(new { action = "Index" })));
                }

                ModelState.Clear();
                if (!ModelState.IsValid)
                {
                    ViewBag.Error = "Please fill all required fields";
                    return(Redirect(Url.RouteUrl(new { action = "Index" })));
                }

                var helper = new UserRegistrationObj
                {
                    Password        = "******",
                    ConfirmPassword = "******",
                    Email           = model.Email,
                    FirstName       = model.FirstName,
                    Surname         = model.LastName,
                    MobileNumber    = model.MobileNo,
                    RoleId          = model.RoleId,
                    UserTypeId      = model.UserTypeId,
                    OrganizationId  = model.OrganizationId,
                    //MyRoleIds = model.MyRoleIds,
                    //MyRoles = selRoles.ToArray(),
                    Username = model.UserName,
                    //SelectedRoles = string.Join(";", selRoles),
                    Sex    = model.SexId,
                    UserId = thisUser.UserId,
                    //IsActive = model.IsApproved
                };

                var retId = PortalUser.UpdateUser(helper);
                if (retId == null)
                {
                    Session["EditError"] = "Unable to update this user";
                    return(Redirect(Url.RouteUrl(new { action = "ModifyUser" })));
                }

                if (!retId.IsSuccessful)
                {
                    Session["EditError"] = string.IsNullOrEmpty(retId.Message.FriendlyMessage) ? "Unable to update this user" : retId.Message.FriendlyMessage;
                    return(Redirect(Url.RouteUrl(new { action = "ModifyUser" })));

                    //Session["Error"] = string.IsNullOrEmpty(retId.Message.FriendlyMessage) ? "Unable to update this organization" : retId.Message.FriendlyMessage;
                    //return Redirect(Url.RouteUrl(new { action = "Index" }));
                }

                //if (retId == null)
                //{
                //    Session["Error"] = "Unable to complete your request! Please try again later";
                //    return Redirect(Url.RouteUrl(new { action = "Index" }));
                //}

                //if (!retId.IsSuccessful)
                //{
                //    Session["Error"] = string.IsNullOrEmpty(retId.Message.FriendlyMessage) ? "Unable to update this user" : retId.Message.FriendlyMessage;
                //    return Redirect(Url.RouteUrl(new { action = "Index" }));
                //}

                Session["_selectedPortalUser"] = null;
                Session["Reply"] = "User information was updated successfully";
                return(Redirect(Url.RouteUrl(new { action = "Index" })));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                BugManager.LogApplicationBug(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }