示例#1
0
        public async Task <ActionResult> Edit(UserProfileModelObject model, HttpPostedFileBase fileUploaderControl)
        {
            try
            {
                UserProfileDTO profile = InsuranceBusiness.BusinessLayer.GetUserProfile(model.ID);

                profile.FirstName = model.FirstName;
                profile.LastName  = model.LastName;
                //profile.User.EmailConfirmed = model.User.EmailConfirmed;

                InsuranceBusiness.BusinessLayer.UpdateProfile(profile);

                UserProfileDTO user = InsuranceBusiness.BusinessLayer.GetUserProfile(model.ID_User);

                if (user.Role.Id != model.Role.Id)
                {
                    RoleDTO roleToRemove = InsuranceBusiness.BusinessLayer.GetRoles().FirstOrDefault(i => i.Id == user.Role.Id);
                    var     result       = await this.UserManager.RemoveFromRoleAsync(model.ID_User, roleToRemove.Name);

                    RoleDTO roleToAssign = InsuranceBusiness.BusinessLayer.GetRoles().FirstOrDefault(i => i.Id == model.Role.Id);
                    result = await this.UserManager.AddToRoleAsync(model.ID_User, roleToAssign.Name);
                }
            }
            catch (Exception ex)
            {
                InsuranceBusiness.BusinessLayer.LogException(string.Format("{0} [{1}]", Request.UserHostAddress, model.ID_User), string.Format("{0}.{1}", this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()), ex);
                return(View("Error"));
            }

            return(RedirectToAction("Index"));
        }
示例#2
0
        public ActionResult Edit(long id = 0)
        {
            UserProfileDTO profile = InsuranceBusiness.BusinessLayer.GetUserProfile(id);

            UserProfileModelObject model = new UserProfileModelObject()
            {
                Active       = profile.Active,
                Address      = profile.Address,
                Birthdate    = profile.Birthdate,
                ContactEmail = profile.ContactEmail,
                FirstName    = profile.FirstName,
                LastName     = profile.LastName,
                ID           = profile.ID,
                ID_User      = profile.ID_User,
                Role         = new RoleModelObject()
                {
                    Id = profile.Role.Id
                },
                User = new UserModelObject()
                {
                    Email             = profile.User.Email,
                    EmailConfirmed    = profile.User.EmailConfirmed,
                    LockoutEnabled    = profile.User.LockoutEnabled,
                    LockoutEndDateUtc = profile.User.LockoutEndDateUtc,
                    Id       = profile.User.Id,
                    UserName = profile.User.UserName
                }
            };

            return(PartialView(model));
        }
示例#3
0
        public ActionResult Create()
        {
            UserProfileModelObject model = new UserProfileModelObject()
            {
                //StartDate = DateTime.Now
            };

            return(PartialView("Create", model));

            //return PartialView(model);
        }
示例#4
0
        public async Task <ActionResult> Create(UserProfileModelObject model, HttpPostedFileBase fileUploaderControl)
        {
            try
            {
                UserProfileDTO newUser = new UserProfileDTO()
                {
                    Active       = true,
                    ContactEmail = model.User.Email,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    User         = new UserDTO()
                    {
                        Email    = model.User.Email,
                        UserName = model.User.Email
                    }
                };

                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser {
                        UserName = model.User.Email, Email = model.User.Email
                    };
                    user.EmailConfirmed = false;
                    string password = GeneratePassword();
                    var    result   = await this.UserManager.CreateAsync(user, password);

                    if (result.Succeeded)
                    {
                        try
                        {
                            RoleDTO role = InsuranceBusiness.BusinessLayer.GetRoles().FirstOrDefault(i => i.Id == model.Role.Id);
                            result = await this.UserManager.AddToRoleAsync(user.Id, role.Name);
                        }
                        catch (Exception ex)
                        {
                            await this.UserManager.DeleteAsync(user);

                            return(View(model));
                        }
                    }

                    long userId = -1;
                    if (result.Succeeded)
                    {
                        try
                        {
                            // Register default profile information!
                            userId = InsuranceBusiness.BusinessLayer.CreateDefaultUserProfile(user.Id, user.UserName, user.Email, model.FirstName, model.LastName, model.ProfessionalNumber);
                        }
                        catch (Exception ex)
                        {
                            await this.UserManager.DeleteAsync(user);

                            return(View(model));
                        }
                    }

                    if (result.Succeeded)
                    {
                        try
                        {
                            InsuranceBusiness.BusinessLayer.CreateNotification(user.Id, null, NotificationTypeEnum.COMPLETE_PROFILE_INFO);

                            string token = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                            token = System.Web.HttpUtility.UrlEncode(token);
                            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { code = user.Id, token = token }, protocol: Request.Url.Scheme);
                            await SendNewRegisterEmail(user, model.FirstName + " " + model.LastName, callbackUrl, password);
                        }
                        catch (Exception ex)
                        {
                            InsuranceBusiness.BusinessLayer.DeleteUserProfile(userId);
                            await this.UserManager.DeleteAsync(user);

                            return(View(model));
                        }

                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        //return View("RegisterToConfirm", model);
                    }
                }
            }
            catch (Exception ex)
            {
                InsuranceBusiness.BusinessLayer.LogException(string.Format("{0} [{1}]", Request.UserHostAddress, model.ID_User), string.Format("{0}.{1}", this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()), ex);
                return(View("Error"));
            }

            return(RedirectToAction("Index"));
        }