public IActionResult JoinEvent(int eventID)
        {
            MemberRepo memRP   = new MemberRepo(_context);
            EventRepo  eventRP = new EventRepo(_context);

            var    claim  = HttpContext.User.Claims.ElementAt(0);
            string email  = claim.Value;
            var    member = memRP.GetOneByEmail(email);

            try
            {
                eventRP.JoinEvent(eventID, member.Id);

                var responseObject = new
                {
                    StatusCode = "Added to the list",
                };
                return(new ObjectResult(responseObject));
            }
            catch
            {
                var responseObject = new
                {
                    error = "can't added again",
                };
                return(new ObjectResult(responseObject));
            }
        }
        public IActionResult leaveEvent(int eventID)
        {
            MemberRepo memRP   = new MemberRepo(_context);
            EventRepo  eventRP = new EventRepo(_context);
            var        claim   = HttpContext.User.Claims.ElementAt(0);
            string     email   = claim.Value;
            var        member  = memRP.GetOneByEmail(email);

            try
            {
                eventRP.leaveEvent(eventID, member.Id);

                var responseObject = new
                {
                    StatusCode = "removed from guest list",
                };
                return(new ObjectResult(responseObject));
            }
            catch
            {
                var responseObject = new
                {
                    error = "Error",
                };
                return(new ObjectResult(responseObject));
            }
        }
        public IActionResult MyEvent()
        {
            UserEventRepo ueRP           = new UserEventRepo(_context);
            MemberRepo    cRP            = new MemberRepo(_context);
            var           claim          = HttpContext.User.Claims.ElementAt(0);
            string        email          = claim.Value;
            var           user           = cRP.GetOneByEmail(email);
            var           query          = ueRP.GetMemberEvents(user.Id);
            var           responseObject = new
            {
                EventArray = query,
            };

            return(new ObjectResult(responseObject));
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync([FromBody] LoginVM loginVM)
        {
            if (ModelState.IsValid)
            {
                var result = await
                             _signInManager.PasswordSignInAsync(loginVM.Email.ToUpper(),
                                                                loginVM.Password, loginVM.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    var UserManager = _serviceProvider.GetRequiredService <UserManager <IdentityUser> >();
                    var user        = await UserManager.FindByEmailAsync(loginVM.Email);

                    MemberRepo cRP      = new MemberRepo(_context);
                    var        userInfo = cRP.GetOneByEmail(loginVM.Email);

                    var userRoleList = _context.UserRoles.Where(ur => ur.UserId == user.Id);

                    string userName = userInfo.userName;
                    if (user != null)
                    {
                        var tokenString = GenerateJSONWebToken(user);
                        var jsonOK      = new
                        {
                            tokenString = tokenString,
                            StatusCode  = "OK",
                            currentUser = loginVM.Email,
                            userName,
                            role = userRoleList
                        };

                        return(new ObjectResult(jsonOK));
                    }
                }
                else if (result.IsLockedOut)
                {
                    var jsonLocked = new { tokenString = "", StatusCode = "Locked out." };
                    return(new ObjectResult(jsonLocked));
                }
            }
            var jsonInvalid = new { tokenString = "", StatusCode = "Invalid Login." };

            return(new ObjectResult(jsonInvalid));
        }