コード例 #1
0
        public IActionResult CompleteProfile()
        {
            CompleteProfileVM vm = new CompleteProfileVM();

            ViewBag.CountryList = new SelectList(GetCountryList(), "CountryId", "CountryName");
            return(View(vm));
        }
コード例 #2
0
        public async Task <IActionResult> CompleteProfile(CompleteProfileVM vm)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetCurrentUser(HttpContext);

                var file = vm.ProfileImage;
                UserPersonalDetail userPersonal = new UserPersonalDetail();
                if (file != null)
                {
                    if (file.Length > 0)
                    {
                        if ((file.Length / 1000) > 5000)
                        {
                            ViewBag.ProfilePic = "Image can't exceed 5Mb size";
                            return(View());
                        }
                        string path      = Path.Combine(_hostingEnvironment.WebRootPath, "images/users");
                        string extension = Path.GetExtension(file.FileName).Substring(1);
                        if (!(extension.ToLower() == "png" || extension.ToLower() == "jpg" || extension.ToLower() == "jpeg"))
                        {
                            ViewBag.ProfilePic = "Only png, jpg & jpeg are allowed";
                            return(View());
                        }
                        string fileNam = user.Id.Substring(24) + "p." + extension;
                        using (var vs = new FileStream(Path.Combine(path, fileNam), FileMode.CreateNew))
                        {
                            await file.CopyToAsync(vs);
                        }
                        using (var img = SixLabors.ImageSharp.Image.Load(Path.Combine(path, fileNam)))
                        {
                            userPersonal.ProfileImage = $"/images/users/{fileNam}";
                        }
                    }
                }
                userPersonal.CityId      = vm.CityId;
                userPersonal.FirstName   = vm.FirstName;
                userPersonal.LastName    = vm.LastName;
                userPersonal.IsDOBPublic = vm.DOBVisibility;
                userPersonal.DOB         = vm.DOB;
                if (vm.Gender == 0)
                {
                    userPersonal.Gender = Gender.Male;
                }
                else
                {
                    userPersonal.Gender = Gender.Female;
                }
                userPersonal.UserId = user.Id;
                _context.UserPersonalDetail.Add(userPersonal);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "User"));
            }
            ViewBag.CountryList = new SelectList(GetCountryList(), "CountryId", "CountryName");
            return(View("CompleteProfile"));
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: fawad1997/TechIn
        public async Task <IActionResult> CompleteProfile()
        {
            var user = await _userManager.GetCurrentUser(HttpContext);

            if (_context.UserPersonalDetail.Where(x => x.UserId == user.Id).Any())
            {
                return(RedirectToAction("Index", "Home"));
            }
            CompleteProfileVM vm = new CompleteProfileVM();

            ViewBag.CountryList = new SelectList(GetCountryList(), "CountryId", "CountryName");
            return(View(vm));
        }