예제 #1
0
        /// <summary>
        /// 组件初始化方法
        /// </summary>
        protected override void OnInitialized()
        {
            Model  = new ProfilesModel(RootLayout?.UserName);
            Themes = new SelectedItem[] { new SelectedItem()
                                          {
                                              Text = "默认样式"
                                          } }.Union(Model.Themes.Select(t => new SelectedItem()
            {
                Text = t.Name, Value = t.Code
            }));
            Apps = Model.Applications.Select(t => new SelectedItem()
            {
                Text = t.Value, Value = t.Key
            });

            SelectedTheme = Themes.First();
            SelectedApp   = Apps.First();

            var user = UserHelper.RetrieveUserByUserName(Model?.UserName);

            if (user != null)
            {
                User = user;
            }

            // 直接绑定 User.DisplayName 导致未保存时 UI 的显示名称也会变化
            DisplayName = User.DisplayName;
        }
예제 #2
0
        public void Process(GlimpsePipelineArgs <ProfilesModel> args)
        {
            Assert.ArgumentNotNull(args, "args");
            var data = new ProfilesModel();

            args.TabData = data;
        }
        public async Task <IActionResult> ChangePassword(ProfilesModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    var result = await _userManager.ChangePasswordAsync(user, model.Password, model.NewPassword);

                    if (!result.Succeeded)
                    {
                        foreach (var error in result.Errors)
                        {
                            ModelState.AddModelError("", error.Description);
                        }

                        return(View("Profiles"));
                    }

                    await _signInManager.SignOutAsync();

                    return(RedirectToAction("Index", "Home"));
                }
            }

            ModelState.AddModelError("", "Invalid request!");

            return(View("Profiles"));
        }
예제 #4
0
        private Task SetChangeMessages(ProfilesModel profileInputValues,
                                       ProfilesModel profileValues, ApplicationDbContext context)
        {
            if (profileInputValues.ProfileImage != Profile.ProfileImage)
            {
                ModelState.AddModelError("Profile.ProfileImage",
                                         $"Current: { profileInputValues.ProfileImage}");
            }

            if (profileInputValues.AccountNumber != Profile.AccountNumber)
            {
                ModelState.AddModelError("Profile.AccountNumber",
                                         $"Current: { profileInputValues.AccountNumber}");
            }

            if (profileInputValues.FirstName != Profile.FirstName)
            {
                ModelState.AddModelError("Profile.FirstName",
                                         $"Current: { profileInputValues.FirstName}");
                profileInputValues.FirstName = "profileInputValues";
                Profile.FirstName            = "ProfileFirstname";
            }

            if (profileInputValues.LastName != Profile.LastName)
            {
                ModelState.AddModelError("Profile.LastName",
                                         $"Current: { profileInputValues.LastName}");
            }

            if (profileInputValues.AddressLine1 != Profile.AddressLine1)
            {
                ModelState.AddModelError("Profile.AddressLine1",
                                         $"Current: { profileInputValues.AddressLine1}");
            }

            if (profileInputValues.AddressLine2 != Profile.AddressLine2)
            {
                ModelState.AddModelError("Profile.AddressLine2",
                                         $"Current: { profileInputValues.AddressLine2}");
            }
            if (profileInputValues.City != Profile.City)
            {
                ModelState.AddModelError("Profile.City",
                                         $"Current: { profileInputValues.City}");
            }

            if (profileInputValues.State != Profile.State)
            {
                ModelState.AddModelError("Profile.State",
                                         $"Current: { profileInputValues.State}");
            }

            if (profileInputValues.ZipCode != Profile.ZipCode)
            {
                ModelState.AddModelError("Profile.ZipCode",
                                         $"Current: { profileInputValues.ZipCode}");
            }

            return(Task.CompletedTask);
        }
예제 #5
0
        public async Task <IActionResult> ProfileCreate(ProfileCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            Profile = new ProfilesModel()
            {
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                AddressLine1 = model.AddressLine1,
                AddressLine2 = model.AddressLine2,
                City         = model.City,
                State        = model.State,
                ZipCode      = model.ZipCode,
                UserId       = user.Id,
                ProfileImage = "000",
            };

            _context.Profiles.Add(Profile);
            await _context.SaveChangesAsync();

            Profile.AccountNumber = DateTime.Now.Year.ToString() + "-" + DateTime.Now.ToString("MM") + "-" +
                                    Profile.Id.ToString().PadLeft(7, '0').
                                    Substring(Profile.Id.ToString().PadLeft(7, '0').Length - 7);

            var userFolder =
                hostingEnvironment.WebRootPath + "\\AppUserData\\" + Profile.AccountNumber + "\\";

            if (!Directory.Exists(userFolder))
            {
                Directory.CreateDirectory(userFolder);
            }

            if (this.UserImage != null)
            {
                var fileExt  = Path.GetExtension(this.UserImage.FileName);
                var fileName = "ProfileImage_001" + fileExt;
                this.UserImage.CopyTo(new FileStream(userFolder + fileName, FileMode.Create));
                Profile.ProfileImage = "001" + fileExt;
            }

            Profile.DateCreate     = DateTime.Now;
            Profile.DateLastUpdate = DateTime.Now;
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(ProfileController.ProfileEditView), "Profile", new { statusMessage = "Profile Successfully Created!" }));
        }
예제 #6
0
        public int SaveOrUpdate(ProfilesModel entity)
        {
            if (entity.ID != 0)
            {
                var dbEntity = ProfilesRepository.Get(entity.ID);
                if (dbEntity != null)
                {
                    ProfilesRepository.Update(dbEntity);

                    return dbEntity.ID;
                }
                throw new ArgumentException("Invalid id");
            }
            return ProfilesRepository.Save(entity);
        }
예제 #7
0
        public async Task <IActionResult> ProfileEditView([Bind("FirstName,LastName,AddressLine1,AddressLine2,City,State,ZipCode,RowVersion")] ProfilesModel profileViewModel)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var ProfileToUpdate = await _context.Profiles
                                  .FirstOrDefaultAsync(m => m.UserId == user.Id);

            if (ProfileToUpdate == null)
            {
                return(RedirectToAction(nameof(ProfileController.ProfileEditView), "Profile"));
            }
            _context.Entry(ProfileToUpdate)
            .Property("RowVersion").OriginalValue = Profile.RowVersion;

            ProfileToUpdate.DateLastUpdate = DateTime.Now;
            if (await TryUpdateModelAsync(
                    ProfileToUpdate, "",
                    p => p.AccountNumber, p => p.FirstName, p => p.LastName,
                    p => p.AddressLine1, p => p.AddressLine2, p => p.City, p => p.State, p => p.ZipCode,
                    p => p.DateLastUpdate))
            {
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(ProfileController.ProfileEditView), "Profile", new { statusMessage = "Profile Successfully Updated!" }));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var exceptionEntry = ex.Entries.Single();
                    var clientValues   = (ProfilesModel)exceptionEntry.Entity;
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        return(RedirectToAction(nameof(ProfileController.ProfileEditView), "Profile"));
                    }

                    ModelState.Remove("Profile.RowVersion");
                }
            }

            return(RedirectToAction(nameof(ProfileController.ProfileEditView), "Profile", new { statusMessage = "NOT Updated ~ Changed By Another", smColor = "orange" }));
        }
        public IActionResult PostProfile([FromBody] ProfilesModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_profileRepository.CreateProfile(Model))
            {
                ModelState.AddModelError("", $"Something went wrong saving the job " +
                                         $"{Model.Id}");
                return(StatusCode(500, ModelState));
            }

            return(Ok(new { userProfileAdded = true }));
        }
예제 #9
0
 public int Save(ProfilesModel entity)
 {
     return ProfilesRepository.Save(entity);
 }
예제 #10
0
 public void Update(ProfilesModel entity)
 {
     ProfilesRepository.Update(entity);
 }
예제 #11
0
 /// <summary>
 /// </summary>
 /// <param name="entity"></param>
 public void Update(ProfilesModel entity)
 {
     CurrentSession.Update(entity);
 }
예제 #12
0
 /// <summary>
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int Save(ProfilesModel entity)
 {
     return (int) CurrentSession.Save(entity);
 }
예제 #13
0
 public IHttpActionResult Save(ProfilesModel item)
 {
     try
     {
         if (item != null)
         {
             ProfilesService.SaveOrUpdate(item);
             return Ok(item);
         }
         return BadRequest("No se ha enviado información que almacenar.");
     }
     catch (HibernateAdoException hibernateException)
     {
         if (hibernateException.InnerException is GenericADOException)
         {
             if (hibernateException.InnerException.InnerException is OracleException)
             {
                 return InternalServerError(hibernateException.InnerException.InnerException);
             }
             return InternalServerError(hibernateException.InnerException);
         }
         return InternalServerError(hibernateException);
     }
     catch (Exception exception)
     {
         return InternalServerError(exception);
     }
 }
예제 #14
0
 public HttpResponseMessage Put([FromUri] Guid id, [FromBody] ProfilesModel item)
 {
     _process.Save(Token: id, UpdatedId: UpdatedId, Profile: item.Profile, Section: item.Section, IsActive: item.IsActive);
     return(new HttpResponseMessage(HttpStatusCode.OK));
 }