public async Task <IActionResult> EditProfile(MyProfileEditViewModel viewModel)
        {
            var userImage = viewModel.User.ImgPath;

            string uniqueFileName = null;

            if (viewModel.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + viewModel.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                viewModel.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
            }


            var currentUser = await GetCurrentUserAsync();

            if (uniqueFileName != null)
            {
                currentUser.ImgPath = uniqueFileName;
            }
            else
            {
                currentUser.ImgPath = userImage;
            }
            var rating = await CalculateRating(currentUser.Id);

            currentUser.Rating = rating;
            //currentUser.ImgPath = uniqueFileName;
            _context.Update(currentUser);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(MyProfile)));
        }
Exemple #2
0
        public bool SaveMyProfileEdit(MyProfileEditViewModel model)
        {
            bool result = false;

            try
            {
                var user = _userRepo.Get(model.UserId);
                if (user != null)
                {
                    user.FirstName   = model.FirstName;
                    user.LastName    = model.LastName;
                    user.DateOfBirth = model.DateOfBirth;
                    user.Description = model.Description;
                    user.GenderId    = model.GenderId;
                    user.ReceiveNews = model.ReceiveNews;
                    user.LanguageId  = model.LanguageId;
                    _userRepo.Edit(user);
                    result = _userRepo.Save();
                }
            }
            catch (Exception e)
            {
                result = false;
                Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "model.UserId = " + model.UserId);
            }
            return(result);
        }
Exemple #3
0
        public MyProfileEditViewModel GetMyProfileEditViewModel(int UserId)
        {
            MyProfileEditViewModel model = new MyProfileEditViewModel();

            try
            {
                var user = _userRepo.Get(UserId);
                if (user != null)
                {
                    model.UserId      = user.Id;
                    model.UserName    = user.AspNetUser.UserName;
                    model.FirstName   = user.FirstName;
                    model.LastName    = user.LastName;
                    model.ReceiveNews = user.ReceiveNews;
                    model.LanguageId  = user.LanguageId;
                    model.Description = user.Description;
                    model.DateOfBirth = user.DateOfBirth;
                    model.GenderId    = user.GenderId;
                }
                model.LanguageList = _categoryService.GetSelectionList(CommonsConst.CategoryTypes.Language);
                model.GenderList   = _categoryService.GetSelectionList(CommonsConst.CategoryTypes.Gender);
            }
            catch (Exception e)
            {
                Commons.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "UserId = " + UserId);
            }
            return(model);
        }
        public async Task <IActionResult> EditProfile()
        {
            MyProfileEditViewModel viewModel = new MyProfileEditViewModel
            {
                User = await GetCurrentUserAsync()
            };

            return(View(viewModel));
        }
Exemple #5
0
        protected async override void OnAppearing()
        {
            Analytics.TrackEvent("MyProfileEditPage");
            base.OnAppearing();

            //Workaround here
            BindingContext = viewModel = Startup.ServiceProvider?.GetService <MyProfileEditViewModel>() ?? new MyProfileEditViewModel();
            await Refresh();
        }