コード例 #1
0
ファイル: AccountController.cs プロジェクト: dilan122/Taxi
        public async Task <IActionResult> ConfirmUserGroup(int requestId, string token)
        {
            if (requestId == 0 || string.IsNullOrEmpty(token))
            {
                return(NotFound());
            }

            UserGroupRequestEntity userGroupRequest = await _context.UserGroupRequests
                                                      .Include(ugr => ugr.ProposalUser)
                                                      .Include(ugr => ugr.RequiredUser)
                                                      .FirstOrDefaultAsync(ugr => ugr.Id == requestId &&
                                                                           ugr.Token == new Guid(token));

            if (userGroupRequest == null)
            {
                return(NotFound());
            }

            await AddGroupAsync(userGroupRequest.ProposalUser, userGroupRequest.RequiredUser);
            await AddGroupAsync(userGroupRequest.RequiredUser, userGroupRequest.ProposalUser);

            userGroupRequest.Status = UserGroupStatus.Accepted;
            _context.UserGroupRequests.Update(userGroupRequest);
            await _context.SaveChangesAsync();

            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> RejectUserGroup(int requestId, string token)
        {
            if (requestId == 0 || string.IsNullOrEmpty(token))
            {
                return(NotFound());
            }

            UserGroupRequestEntity userGroupRequest = await _context
                                                      .UserGroupRequests.FirstOrDefaultAsync(ugr => ugr.Id == requestId && ugr.Token == new Guid(token));

            if (userGroupRequest == null)
            {
                return(NotFound());
            }

            userGroupRequest.Status = UserGroupStatus.Rejected;
            _context.UserGroupRequests.Update(userGroupRequest);
            await _context.SaveChangesAsync();

            return(View());
        }
コード例 #3
0
        public async Task <IActionResult> PostUserGroup([FromBody] AddUserGroupRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CultureInfo cultureInfo = new CultureInfo(request.CultureInfo);

            Resource.Culture = cultureInfo;

            UserEntity proposalUser = await _userHelper.GetUserAsync(request.UserId);

            if (proposalUser == null)
            {
                return(BadRequest(Resource.UserNotFoundError));
            }

            UserEntity requiredUser = await _userHelper.GetUserAsync(request.Email);

            if (requiredUser == null)
            {
                return(BadRequest(Resource.UserNotFoundError));
            }

            UserGroupEntity userGroup = await _context.UserGroupEntities
                                        .Include(ug => ug.Users)
                                        .ThenInclude(u => u.User)
                                        .FirstOrDefaultAsync(ug => ug.User.Id == request.UserId.ToString());

            if (userGroup != null)
            {
                UserGroupDetailEntity user = userGroup.Users.FirstOrDefault(u => u.User.Email == request.Email);
                if (user != null)
                {
                    return(BadRequest(Resource.UserAlreadyBelogToGroup));
                }
            }

            UserGroupRequestEntity userGroupRequest = new UserGroupRequestEntity
            {
                ProposalUser = proposalUser,
                RequiredUser = requiredUser,
                Status       = UserGroupStatus.Pending,
                Token        = Guid.NewGuid()
            };

            try
            {
                _context.UserGroupRequestEntities.Add(userGroupRequest);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string linkConfirm = Url.Action("ConfirmUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            string linkReject = Url.Action("RejectUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            Response response = _mailHelper.SendMail(request.Email, Resource.RequestJoinGroupSubject, $"<h1>{Resource.RequestJoinGroupSubject}</h1>" +
                                                     $"{Resource.TheUser}: {proposalUser.FullName} ({proposalUser.Email}), {Resource.RequestJoinGroupBody}" +
                                                     $"</hr></br></br>{Resource.WishToAccept} <a href = \"{linkConfirm}\">{Resource.Confirm}</a>" +
                                                     $"</hr></br></br>{Resource.WishToReject} <a href = \"{linkReject}\">{Resource.Reject}</a>");

            if (!response.IsSuccess)
            {
                return(BadRequest(response.Message));
            }

            return(Ok(Resource.RequestJoinGroupEmailSent));
        }
コード例 #4
0
        public async Task <IActionResult> PostUserGroup([FromBody] AddUserGroupRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            UserEntity proposalUser = await _userHelper.GetUserAsync(request.UserId);

            if (proposalUser == null)
            {
                return(BadRequest("Este Usuario no existe."));
            }

            UserEntity requiredUser = await _userHelper.GetUserAsync(request.Email);

            if (requiredUser == null)
            {
                return(BadRequest("Este Usuario no existe."));
            }

            UserGroupEntity userGroup = await _context.UserGroups
                                        .Include(ug => ug.Users)
                                        .ThenInclude(u => u.User)
                                        .FirstOrDefaultAsync(ug => ug.User.Id == request.UserId.ToString());

            if (userGroup != null)
            {
                UserGroupDetailEntity user = userGroup.Users.FirstOrDefault(u => u.User.Email == request.Email);
                if (user != null)
                {
                    return(BadRequest("Este Usuario ya pertenece al Grupo."));
                }
            }

            UserGroupRequestEntity userGroupRequest = new UserGroupRequestEntity
            {
                ProposalUser = proposalUser,
                RequiredUser = requiredUser,
                Status       = UserGroupStatus.Pending,
                Token        = Guid.NewGuid()
            };

            try
            {
                _context.UserGroupRequests.Add(userGroupRequest);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string linkConfirm = Url.Action("ConfirmUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            string linkReject = Url.Action("RejectUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            Response response = _mailHelper.SendMail(request.Email, "Solicitud de unirse a un Grupo", $"<h1>Solicitud de unirse a un Grupo</h1>" +
                                                     $"El Usuario: {proposalUser.FullName} ({proposalUser.Email}), ha solicitado que sea miembro de su grupo de usuarios en la aplicación TAXI." +
                                                     $"</hr></br></br>Si desea aceptar, haga clic aquí: <a href = \"{linkConfirm}\">Confirmar</a>" +
                                                     $"</hr></br></br>Si desea rechazar, haga clic aquí: <a href = \"{linkReject}\">Rechazar</a>");

            if (!response.IsSuccess)
            {
                return(BadRequest(response.Message));
            }

            return(Ok("Se ha enviado un correo electrónico al usuario con su solicitud, esperamos a que responda pronto!"));
        }
コード例 #5
0
        public async Task <IActionResult> PostUserGroup([FromBody] AddUserGroupRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            UserEntity proposalUser = await _userHelper.GetUserAsync(request.UserId);

            if (proposalUser == null)
            {
                return(BadRequest());
            }

            UserEntity requiredUser = await _userHelper.GetUserAsync(request.Email);

            if (requiredUser == null)
            {
                return(BadRequest());
            }

            UserGroupEntity userGroup = await _context.UserGroups
                                        .Include(ug => ug.Users)
                                        .ThenInclude(u => u.User)
                                        .FirstOrDefaultAsync(ug => ug.User.Id == request.UserId.ToString());

            if (userGroup != null)
            {
                UserGroupDetailEntity user = userGroup.Users.FirstOrDefault(u => u.User.Email == request.Email);
                if (user != null)
                {
                    return(BadRequest());
                }
            }

            UserGroupRequestEntity userGroupRequest = new UserGroupRequestEntity
            {
                ProposalUser = proposalUser,
                RequiredUser = requiredUser,
                Status       = UserGroupStatus.Pending,
                Token        = Guid.NewGuid()
            };

            try
            {
                _context.UserGroupRequests.Add(userGroupRequest);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string linkConfirm = Url.Action("ConfirmUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            string linkReject = Url.Action("RejectUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            Response response = _mailHelper.SendMail(request.Email, "user request", $"<h1>{"User group"}</h1>" +
                                                     $"{"convert user helper"}: {proposalUser.FullName} ({proposalUser.Email}), {"passs body"}" +
                                                     $"</hr></br></br>{"Sccept"} <a href = \"{linkConfirm}\">{"Confirm"}</a>" +
                                                     $"</hr></br></br>{"in join"} <a href = \"{linkReject}\">{"Reject"}</a>");

            if (!response.IsSuccess)
            {
                return(BadRequest(response.Message));
            }

            return(Ok());
        }
コード例 #6
0
        public async Task <IActionResult> PostUserGroup([FromBody] AddUserGroupRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            UserEntity proposalUser = await _userHelper.GetUserAsync(request.UserId);

            if (proposalUser == null)
            {
                return(BadRequest("Error, Usuario no existe"));
            }

            UserEntity requiredUser = await _userHelper.GetUserAsync(request.Email);

            if (requiredUser == null)
            {
                return(BadRequest("Error, Usuario no existe"));
            }

            UserGroupEntity userGroup = await _context.UserGroups
                                        .Include(ug => ug.Users)
                                        .ThenInclude(u => u.User)
                                        .FirstOrDefaultAsync(ug => ug.User.Id == request.UserId.ToString());

            if (userGroup != null)
            {
                UserGroupDetailEntity user = userGroup.Users.FirstOrDefault(u => u.User.Email == request.Email);
                if (user != null)
                {
                    return(BadRequest("El ususario ya esta registrado al grupo"));
                }
            }

            UserGroupRequestEntity userGroupRequest = new UserGroupRequestEntity
            {
                ProposalUser = proposalUser,
                RequiredUser = requiredUser,
                Status       = UserGroupStatus.Pending,
                Token        = Guid.NewGuid()
            };

            try
            {
                _context.UserGroupRequests.Add(userGroupRequest);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string linkConfirm = Url.Action("ConfirmUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            string linkReject = Url.Action("RejectUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            Response response = _mailHelper.SendMail(request.Email, "Asunto: Solicitar unirse al grupo", $"<h1> Asunto: Solicitar unirse al grupo </h1>" +
                                                     $"El Usuario: {proposalUser.FullName} ({proposalUser.Email}), Solicita que te unas al grupo" +
                                                     $"</hr></br></br> Deseo confirmar <a href = \"{linkConfirm}\">Confirma aqui </a>" +
                                                     $"</hr></br></br> Si deseas rechazar <a href = \"{linkReject}\"> Rechaza aqui </a>");

            if (!response.IsSuccess)
            {
                return(BadRequest(response.Message));
            }

            return(Ok("Solicitud para unirse al grupo ha sido enviada al correo electrónico."));
        }
コード例 #7
0
ファイル: UserGroupsController.cs プロジェクト: ODAJIM17/Taxi
        public async Task <IActionResult> PostUserGroup([FromBody] AddUserGroupRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //CultureInfo cultureInfo = new CultureInfo(request.CultureInfo);
            //Resource.Culture = cultureInfo;

            UserEntity proposalUser = await _userHelper.GetUserAsync(request.UserId);

            if (proposalUser == null)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "User not found"
                }));
            }

            UserEntity requiredUser = await _userHelper.GetUserAsync(request.Email);

            if (requiredUser == null)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "User not found"
                }));
            }

            UserGroupEntity userGroup = await _context.UserGroups
                                        .Include(ug => ug.Users)
                                        .ThenInclude(u => u.User)
                                        .FirstOrDefaultAsync(ug => ug.User.Id == request.UserId.ToString());

            if (userGroup != null)
            {
                UserGroupDetailEntity user = userGroup.Users.FirstOrDefault(u => u.User.Email == request.Email);
                if (user != null)
                {
                    return(BadRequest(new Response
                    {
                        IsSuccess = false,
                        Message = "User already belongs to a group"
                    }));
                }
            }

            UserGroupRequestEntity userGroupRequest = new UserGroupRequestEntity
            {
                ProposalUser = proposalUser,
                RequiredUser = requiredUser,
                Status       = UserGroupStatus.Pending,
                Token        = Guid.NewGuid()
            };

            try
            {
                _context.UserGroupRequests.Add(userGroupRequest);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            string linkConfirm = Url.Action("ConfirmUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            string linkReject = Url.Action("RejectUserGroup", "Account", new
            {
                requestId = userGroupRequest.Id,
                token     = userGroupRequest.Token
            }, protocol: HttpContext.Request.Scheme);

            Response response = _mailHelper.SendMail(request.Email, "Request To Join Group", $"<h1>{"Invitation to join a user group"}</h1>" +
                                                     $"{"User"}: {proposalUser.FullName} ({proposalUser.Email}), {" Has Invite you to join a user group for the Taxi Survey Application."}" +
                                                     $"</hr></br></br>{"If you wish to accept, clik here"} <a href = \"{linkConfirm}\">{"Confirm"}</a>" +
                                                     $"</hr></br></br>{"If you wish To Reject, clck here"} <a href = \"{linkReject}\">{"Not Inerested"}</a>");

            if (!response.IsSuccess)
            {
                return(BadRequest(response.Message));
            }

            return(Ok("Request To Join a Group EmailSent"));
        }