Ejemplo n.º 1
0
        public ActionResult Settings()
        {
            UserProfileVm profile = null;

            if (LoggedInUser == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (string.IsNullOrEmpty(LoggedInUser?.ApiKey))
            {
                var user = Db.Users.FirstOrDefault(x => x.Id == LoggedInUser.Id);
                if (user != null)
                {
                    user.ApiKey = KeyGenerator.GetUniqueKey(32);
                }
                Db.SaveChanges();
                SetupLoggedInUser(LoggedInUser.UserName);
            }

            profile = new UserProfileVm()
            {
                UserName  = LoggedInUser.UserName,
                FirstName = LoggedInUser.FirstName,
                LastName  = LoggedInUser.LastName,
                Email     = LoggedInUser.Email,
                IsUsesApi = LoggedInUser.IsUsesApi,
                ApiKey    = LoggedInUser.ApiKey,
            };

            return(View("Settings", profile));
        }
        public ActionResult AddProfile(UserProfileBm bm)
        {
            if (!this.ModelState.IsValid)
            {
                var vm = new UserProfileVm();
                vm.FirstName   = bm.FirstName;
                vm.LastName    = bm.LastName;
                vm.CityName    = bm.CityName;
                vm.CountryName = bm.CountryName;

                foreach (var kvp in this.ModelState)
                {
                    if (kvp.Value.Errors.Count > 0)
                    {
                        var errorMsg =
                            this.langManager.GetLanguageValueByKey(kvp.Value.Errors.FirstOrDefault().ErrorMessage,
                                                                   this.langManager.GetCurrentLang(this.HttpContext).TwoLetterCode);
                        vm.Errors.Add(kvp.Key, errorMsg);
                    }
                }

                this.TempData["errorModel"] = vm;

                return(this.RedirectToAction("AddProfile"));
            }

            var isSuccess = this.myUserManager.AddUserDetails(bm, this.User.Identity.GetUserId());

            if (!isSuccess)
            {
                //error page
            }

            return(this.RedirectToAction("UserProfile"));
        }
        public ActionResult AddProfile()
        {
            var vm = this.TempData["errorModel"] as UserProfileVm;

            if (vm == null)
            {
                vm = new UserProfileVm();
            }
            this.TempData["errorModel"] = null;

            vm.LanguageCode = this.CurrentLanguageCode;

            return(this.View(vm));
        }
        public UserProfileVm GetMyProfileVm(User user)
        {
            var viewModel = new UserProfileVm();

            viewModel.Id              = user.Id;
            viewModel.Username        = user.Username;
            viewModel.Phone           = user.Phone;
            viewModel.Email           = user.Email;
            viewModel.InStockCameras  = user.Cameras.Count(x => x.Quantity > 0);
            viewModel.OutStockCameras = user.Cameras.Count(x => x.Quantity == 0);
            viewModel.UserCameras     = Mapper.Map <IEnumerable <Camera>, IEnumerable <AllCamerasVm> >(user.Cameras);

            return(viewModel);
        }
        public ActionResult UserProfile()
        {
            var appUserId = this.User.Identity.GetUserId();

            UserProfileVm vm = this.myUserManager.GetUserProfileByAppUserId(appUserId);

            if (vm == null)
            {
                return(this.RedirectToAction("AddProfile"));
            }

            vm.LanguageCode = this.CurrentLanguageCode;

            return(this.View(vm));
        }
Ejemplo n.º 6
0
        public ActionResult Settings(UserProfileVm profile)
        {
            var user = Db.Users.FirstOrDefault(x => x.Id == LoggedInUser.Id);

            if (user == null)
            {
                return(View("Error"));
            }

            user.FirstName = profile.FirstName;
            user.LastName  = profile.LastName;
            user.Email     = profile.Email;
            Db.SaveChanges();

            SetupLoggedInUser(LoggedInUser.UserName);

            TempData["Success"] = "Settings has been saved successfully!";
            return(RedirectToAction("Settings"));
        }
        //[ChildActionOnly]
        //public PartialViewResult LoginPartial()
        //{
        //    return PartialView("_LoginPartial");
        //}
        //[ChildActionOnly]
        //public PartialViewResult SignupPartial()
        //{
        //    return PartialView("_SignupPartial");
        //}

        public ActionResult UserProfile(int id)
        {
            var user     = userService.GetById(id);
            var userRole = userRoleService.GetByUserId(id);

            if (userRole.Count() > 1)
            {
                ViewBag.IsAdmin = true;
            }
            else
            {
                ViewBag.IsAdmin = false;
            }
            var post          = postService.GetByUserId(id);
            var userProfileVm = new UserProfileVm();

            userProfileVm.Users = user;
            userProfileVm.Posts = post;
            return(View(userProfileVm));
        }
        public UserProfileVm GetUserProfileVm(string username)
        {
            var user = this.data.Context.Users.FirstOrDefault(x => x.Username == username);

            if (user == null)
            {
                return(null);
            }

            var viewModel = new UserProfileVm();

            viewModel.Id              = user.Id;
            viewModel.Username        = user.Username;
            viewModel.Phone           = user.Phone;
            viewModel.Email           = user.Email;
            viewModel.InStockCameras  = user.Cameras.Count(x => x.Quantity > 0);
            viewModel.OutStockCameras = user.Cameras.Count(x => x.Quantity == 0);
            viewModel.UserCameras     = Mapper.Map <IEnumerable <Camera>, IEnumerable <AllCamerasVm> >(user.Cameras);

            return(viewModel);
        }
Ejemplo n.º 9
0
        public JsonResult UpdateUserProfile([FromBody] UserProfileVm model)
        {
            lock (myLock) // HACK: arrgghh we keep gertting two simultaneous requests!
            {
                if (!User.Identity.IsAuthenticated)
                {
                    Response.StatusCode = 403;
                    return(null);
                }
                if (!ModelState.IsValid)
                {
                    return(Json(ModelState.ToErrorsDictionary()));
                }


                var userProfile = _dataContext.Users
                                  .Include(u => u.AccessibilityNeeds)
                                  .ThenInclude(an => an.AccessibilityNeed)
                                  .FirstOrDefault(u => u.UserName == User.Identity.Name);
                var reloadedModel = UserProfileVmMappings.ToEntity(_dataContext, model, userProfile);
                return(Json(reloadedModel));
            }
        }