public async Task <IActionResult> Create([Bind("Id,UserId,ProfilePicture,IsDefault")] UserPicture userPicture, IFormFile ProfilePicture)
        {
            string sImagePath          = GetImagePath(UserId);
            string sImageThumbnailPath = GetThumbnailImagePath(UserId);



            var path      = Path.Combine(sImagePath, ProfilePicture.FileName);
            var thumbpath = Path.Combine(sImageThumbnailPath, ProfilePicture.FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await ProfilePicture.CopyToAsync(stream);
            }

            Crop(200, 200, ProfilePicture.OpenReadStream(), thumbpath);



            userPicture.UserId         = UserId;
            userPicture.ProfilePicture = ProfilePicture.FileName;
            _context.Add(userPicture);

            if (ProfilePicture == null || ProfilePicture.Length == 0)
            {
                return(Content("file not selected"));
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,EmailAddress,PhoneNumber,Gender,DateOfBirth,RegistrationDate,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,UserId,ProfileId,Message,SentDate")] UserMessage userMessage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userMessage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userMessage));
        }
        public async Task <IActionResult> Create([Bind("Id,UserId,ContactName,RelationShip,ContactNumber,ContactAddress")] UserContact userContact)
        {
            if (ModelState.IsValid)
            {
                userContact.UserId = UserId;
                _context.Add(userContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userContact));
        }
Esempio n. 5
0
        public async Task <IActionResult> Login(LoginViewModel loginViewModel)
        {
            try
            {
                var user = db.User.Where(x => x.EmailAddress == loginViewModel.UserName && x.Password == loginViewModel.Password).FirstOrDefault();
                if (user != null)
                {
                    var identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, user.Name),
                        new Claim(ClaimTypes.Email, user.EmailAddress),
                        new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                        new Claim(ClaimTypes.Role, user.Role),
                    }, CookieAuthenticationDefaults.AuthenticationScheme);

                    var principal = new ClaimsPrincipal(identity);


                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                    if (db.UserLogin.Any(x => x.UserId == user.Id))
                    {
                        LastLoginId = db.UserLogin.Where(x => x.UserId == user.Id).Max(x => x.Id);
                    }

                    db.UserLogin.Add(new UserLogin()
                    {
                        LoginDate = DateTime.Now, UserId = user.Id, LastLoginId = LastLoginId
                    });
                    await db.SaveChangesAsync();
                }
                else
                {
                    ModelState.AddModelError("UserName", "Username and Password not valid");
                    return(RedirectToAction("Login"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("ErrorNotLoggedIn"));
            }
            return(RedirectToAction("Index", "Home"));
        }