Example #1
0
        public string Login(string EmailId, string Password)
        {
            logger.Error("Checking Abhay123");
            try
            {
                UserRepository userrepo = new UserRepository();
                Domain.Socioboard.Domain.User user = userrepo.GetUserInfo(EmailId, Utility.MD5Hash(Password));
                if (user != null)
                {
                    if (user.UserCode == null || user.UserCode == "")
                    {
                        string code = Utility.GenerateRandomUniqueString();
                        int retint = userrepo.UpdateCode(user.Id, code);
                        user = userrepo.getUsersById(user.Id);
                    }
                    return new JavaScriptSerializer().Serialize(user);

                }
                else
                {
                    return new JavaScriptSerializer().Serialize("Not Exist");
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error : " + ex.Message);
                logger.Error("Error : " + ex.StackTrace);
                Console.WriteLine(ex.StackTrace);
                return null;
            }
        }
        //public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        //{
        //    context.OwinContext.Response.Headers.Add("access-control-allow-origin", new[] { "*" });

        //    //we check if the passed username and password are correct.
        //    if (context.UserName == "user" && context.Password == "pwd")
        //    {
        //        System.Security.Claims.ClaimsIdentity ci = new System.Security.Claims.ClaimsIdentity("ci");
        //        //this indicates that user is valid one and can be issued a token.
        //        //it has several overloads ,you can take what fits for you.I have used it with ClaimsIdentity
        //        context.Validated(ci);
        //    }
        //    else
        //    {
        //        // a custom error message can be returned to client before rejecting the request.
        //        context.SetError("Incorrect Credentials");
        //        context.Rejected();
        //    }
        //    return ;
        //}


        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            string allowedOrigin = "*";

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Content-Type" });

            
                UserRepository userrepo = new UserRepository();
                try {
                    Domain.Socioboard.Domain.User user = userrepo.GetUserInfo(context.UserName, context.Password);
                    if (user != null)
                    {


                        ClaimsIdentity identity = new ClaimsIdentity("User");

                        identity.AddClaim(new Claim(ClaimTypes.Name, user.Id.ToString()));
                        if (string.IsNullOrEmpty(user.UserType)) 
                        {
                            identity.AddClaim(new Claim(ClaimTypes.Role, "User")); 
                        }
                        else if (!string.IsNullOrEmpty(user.UserType) && user.UserType.Equals("SuperAdmin"))
                        {
                            identity.AddClaim(new Claim(ClaimTypes.Role, "SuperAdmin"));
                        }
                        else
                        {
                            identity.AddClaim(new Claim(ClaimTypes.Role, "User"));
                        }
                        //foreach (string claim in user.Claims)
                        //{
                        //    identity.AddClaim(new Claim("Claim", claim));
                        //}

                        var ticket = new AuthenticationTicket(identity, null);
                        context.Validated(ticket);
                    }
                    else
                    {
                        context.SetError("Incorrect Credentials");
                        context.Rejected();
                    }

                }catch(Exception e){}
               
        }
        //[WebMethod]
        //[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
        public string SendNewsLetter(string body, string Subject, string userid,string NewsLetterId)
        {
            
            UserRepository objUserRepository = new UserRepository();
            Domain.Socioboard.Domain.User objUser = new Domain.Socioboard.Domain.User();
            string res = string.Empty;
            string ret = string.Empty;
            try
            {


                string from = ConfigurationManager.AppSettings["fromemail"];
                string tomail = ConfigurationManager.AppSettings["tomail"];
                string username = ConfigurationManager.AppSettings["Mandrillusername"];
                string host = ConfigurationManager.AppSettings["Mandrillhost"];
                string port = ConfigurationManager.AppSettings["Mandrillport"];
                string pass = ConfigurationManager.AppSettings["Mandrillpassword"];


                //string sss = ConfigurationSettings.AppSettings["host"];
                objUser = objUserRepository.getUsersById(Guid.Parse(userid));

                GlobusMailLib.MailHelper objMailHelper = new GlobusMailLib.MailHelper();

                ret = objMailHelper.SendMailByMandrill(host, Convert.ToInt32(port), from, "", objUser.EmailId, string.Empty, string.Empty, Subject, body, username, pass);
                //NewsLetterRepository objNewsLetterRepository = new NewsLetterRepository();

                if (ret.Contains("Success"))
                {
                    ObjNewsLetter.Id = Guid.Parse(NewsLetterId);
                    ObjNewsLetter.SendStatus = true;
                    ObjNewsLetterRepository.UpdateNewsLetter(ObjNewsLetter);
                    //lstbox.Items.Add("Mail send to : " + objUser.UserName);
                }
                //return ret;

                
            }
            catch (Exception ex)
            {

                Console.WriteLine("Error : " + ex.StackTrace);
            }
            return ret;
        }
        //public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        //{
        //    context.OwinContext.Response.Headers.Add("access-control-allow-origin", new[] { "*" });

        //    //we check if the passed username and password are correct.
        //    if (context.UserName == "user" && context.Password == "pwd")
        //    {
        //        System.Security.Claims.ClaimsIdentity ci = new System.Security.Claims.ClaimsIdentity("ci");
        //        //this indicates that user is valid one and can be issued a token.
        //        //it has several overloads ,you can take what fits for you.I have used it with ClaimsIdentity
        //        context.Validated(ci);
        //    }
        //    else
        //    {
        //        // a custom error message can be returned to client before rejecting the request.
        //        context.SetError("Incorrect Credentials");
        //        context.Rejected();
        //    }
        //    return ;
        //}


        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            string allowedOrigin = "*";

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Content-Type" });

            
                UserRepository userrepo = new UserRepository();
                try {
                    Domain.Socioboard.Domain.User user = userrepo.GetUserInfo(context.UserName, Utility.MD5Hash(context.Password));
                    if (user != null)
                    {

                        Api.Socioboard.Helper.UserManager.User apiUser = new Api.Socioboard.Helper.UserManager.User();
                        apiUser.UserName = user.UserName;
                        apiUser.EmailId = user.EmailId;
                        apiUser.Id = user.Id;

                        ClaimsIdentity identity = new ClaimsIdentity("User");

                        identity.AddClaim(new Claim(ClaimTypes.Name, apiUser.Id.ToString()));
                        
                        //foreach (string claim in user.Claims)
                        //{
                        //    identity.AddClaim(new Claim("Claim", claim));
                        //}

                        var ticket = new AuthenticationTicket(identity, null);
                        context.Validated(ticket);
                    }
                    else
                    {
                        context.SetError("Incorrect Credentials");
                        context.Rejected();
                    }

                }catch(Exception e){}
               
        }
        public IHttpActionResult FacebookPostsCommentsService()
        {
            Facebook.FacebookClient fb = new Facebook.FacebookClient();
            UserRepository userRepo = new UserRepository();
            FacebookAccountRepository fbAccRepo = new FacebookAccountRepository();
            Api.Socioboard.Services.Facebook fbService = new Api.Socioboard.Services.Facebook();
            List<Domain.Socioboard.Domain.User> lstUser = new List<Domain.Socioboard.Domain.User>();
            lstUser = userRepo.getAllUsers();
            foreach (var user in lstUser)
            {
                List<Domain.Socioboard.Domain.FacebookAccount> lstFacebookAccount = fbAccRepo.GetAllFacebookAccountByUserId(user.Id);

                foreach (var fbAcc in lstFacebookAccount)
                {
                    if (!string.IsNullOrEmpty(fbAcc.AccessToken))
                    {
                        fb.AccessToken = fbAcc.AccessToken;
                        MongoRepository boardrepo = new MongoRepository("MongoFacebookFeed");
                        try
                        {

                            var result = boardrepo.Find<MongoFacebookFeed>(x => x.ProfileId.Equals(fbAcc.FbUserId) && x.UserId.Equals(user.Id.ToString())).ConfigureAwait(false);

                            var task = Task.Run(async () =>
                            {
                                return await result;
                            });
                            IList<MongoFacebookFeed> objfbfeeds = task.Result;
                            if (objfbfeeds.Count() == 0)
                            {

                                result = boardrepo.Find<MongoFacebookFeed>(x => x.ProfileId.Equals(fbAcc.FbUserId)).ConfigureAwait(false);

                                task = Task.Run(async () =>
                                {
                                    return await result;
                                });
                            }
                            List<MongoFacebookFeed> fbfeeds = objfbfeeds.ToList();
                            foreach (var post in fbfeeds)
                            {
                                fbService.AddFbPostComments(post.FeedId, fb, user.Id.ToString());
                            }

                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                            logger.Error(ex.StackTrace);
                            return BadRequest("Something Went Wrong");
                        }
                    }



                }



            }


            return Ok();
        }
Example #6
0
        public string GetAllTaskByUserIdAndGroupId(string userid, string username, string profileurl, string days, string groupid)
        {
            UserRepository userrepo = new UserRepository();
            Guid UserId = Guid.Parse(userid);
            List<Domain.Socioboard.Domain.Tasks> taskdata = new List<Domain.Socioboard.Domain.Tasks>();
            List<Domain.Socioboard.Domain.TaskByUser> taskbyuser = new List<Domain.Socioboard.Domain.TaskByUser>();
            TaskByUser _TaskByUser = new TaskByUser();
            TaskRepository taskrepo = new TaskRepository();
            taskdata = taskrepo.getAllTasksOfUserBYDays(Guid.Parse(userid), Guid.Parse(groupid), Convert.ToInt32(days));
            foreach (var item in taskdata)
            {
                _TaskByUser.TaskMessage = item.TaskMessage;
                _TaskByUser.TaskStatus = item.TaskStatus;
                _TaskByUser.AssignDate = item.AssignDate;
                _TaskByUser.CompletionDate = item.CompletionDate;
                try
                {
                    if (UserId == item.AssignTaskTo)
                    {
                        _TaskByUser.AssignToUserName = username;
                    }
                    else
                    {
                        Domain.Socioboard.Domain.User User = userrepo.getUsersById(item.AssignTaskTo);
                        _TaskByUser.AssignToUserName = User.UserName;

                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    if (UserId == item.UserId)
                    {
                        _TaskByUser.AssignByUserName = username;
                    }
                    else
                    {
                        Domain.Socioboard.Domain.User User = userrepo.getUsersById(item.UserId);
                        _TaskByUser.AssignByUserName = User.UserName;

                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }

                _TaskByUser.days = Convert.ToInt32(days);
                _TaskByUser.UserName = username;
                _TaskByUser.ProfileUrl = profileurl;
                taskbyuser.Add(_TaskByUser);
            }
            return new JavaScriptSerializer().Serialize(taskbyuser);
        }
Example #7
0
        public string ChangePasswordWithoutOldPassword(string EmailId, string Password, string NewPassword)
        {

            try
            {
                User user = new User();
                UserRepository userrepo = new UserRepository();
                int i = userrepo.ChangePasswordWithoutOldPassword(Utility.MD5Hash(NewPassword), EmailId);
                if (i == 1)
                {
                    return "Password Changed Successfully";
                }
                else
                {
                    return "Invalid EmailId";
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return "Please Try Again";
            }
        }
Example #8
0
        public string ChangePassword(string EmailId, string Password, string NewPassword, string access_token)
        {
            //if (!User.Identity.IsAuthenticated)
            //{
            //    return "Unauthorized access";
            //}
            try
            {
                User user = new User();
                UserRepository userrepo = new UserRepository();
                int i = userrepo.ChangePassword(Utility.MD5Hash(NewPassword), Utility.MD5Hash(Password), EmailId);
                if (i == 1)
                {
                    return "Password Changed Successfully";
                }
                else
                {
                    return "Invalid EmailId";
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return "Please Try Again";
            }
        }
Example #9
0
        private static Domain.Socioboard.Domain.Groups AddGroupByUserId(Guid userId)
        {
            Domain.Socioboard.Domain.Groups groups = new Domain.Socioboard.Domain.Groups();
            GroupsRepository objGroupRepository = new GroupsRepository();
            UserRepository userRepo = new UserRepository();
            GroupMembersRepository grpMemberRepo = new GroupMembersRepository();

            groups.Id = Guid.NewGuid();
            groups.GroupName = ConfigurationManager.AppSettings["DefaultGroupName"];
            groups.UserId = userId;
            groups.EntryDate = DateTime.UtcNow;

            objGroupRepository.AddGroup(groups);

            Domain.Socioboard.Domain.User objUser = userRepo.getUsersById(groups.UserId);
            Domain.Socioboard.Domain.Groupmembers grpMember = new Domain.Socioboard.Domain.Groupmembers();
            grpMember.Id = Guid.NewGuid();
            grpMember.Groupid = groups.Id.ToString();
            grpMember.Userid = groups.UserId.ToString();
            grpMember.Status = Domain.Socioboard.Domain.GroupUserStatus.Accepted;
            grpMember.Emailid = objUser.EmailId;
            grpMember.IsAdmin = true;
            grpMemberRepo.AddGroupMemeber(grpMember);


            return groups;
        }
        public string GetTicketsofGroup(string GroupId, string UserId)
        {
            string AssignedUser = string.Empty;
            try
            {
                GroupProfileRepository objGroupProfileRepository = new GroupProfileRepository();
                FacebookFeedRepository objFacebookFeedRepository = new FacebookFeedRepository();
                TwitterFeedRepository objTwitterFeedRepository = new TwitterFeedRepository();
                List<Domain.Socioboard.Domain.FeedSentimentalAnalysis> lstNegativeFeedsOfUser = new List<Domain.Socioboard.Domain.FeedSentimentalAnalysis>();
                List<Domain.Socioboard.Domain.GroupProfile> objGroupProfile = new List<Domain.Socioboard.Domain.GroupProfile>();
                List<FBTwitterFeeds> objListFBTwitterFeeds = new List<FBTwitterFeeds>();

                objGroupProfile = objGroupProfileRepository.getAllGroupProfiles(Guid.Parse(UserId), Guid.Parse(GroupId));

                if (objGroupProfile.Count > 0)
                {
                    lstNegativeFeedsOfUser = _FeedSentimentalAnalysisRepository.getAllNegativeFeedsOfUser(Guid.Parse(UserId));
                }
                else
                {
                    lstNegativeFeedsOfUser = _FeedSentimentalAnalysisRepository.getNegativeFeedsOfUser(Guid.Parse(UserId));
                }
                if (lstNegativeFeedsOfUser != null)
                {
                    foreach (var item in lstNegativeFeedsOfUser)
                    {
                        FBTwitterFeeds objFBTwitterFeeds = new FBTwitterFeeds();
                        UserRepository objUserRepository = new UserRepository();
                        Domain.Socioboard.Domain.User user = objUserRepository.getUsersById(item.AssigneUserId);
                        if (objGroupProfileRepository.checkProfileExistsingroup(Guid.Parse(GroupId), item.ProfileId))
                        {
                            string Network = item.Network;
                            if (Network == "facebook")
                            {
                                Domain.Socioboard.Domain.FacebookFeed facebookfeed = objFacebookFeedRepository.getFacebookFeedByProfileId(item.ProfileId, item.FeedId);
                                if (facebookfeed != null)
                                {
                                    objFBTwitterFeeds.FacebookFeed = facebookfeed;
                                }
                            }
                            if (Network == "twitter")
                            {
                                Domain.Socioboard.Domain.TwitterFeed twtfeed = objTwitterFeedRepository.getTwitterFeedByProfileId(item.ProfileId, item.FeedId);
                                if (twtfeed != null)
                                {
                                    objFBTwitterFeeds.TwitterFeed = twtfeed;
                                }
                            }
                            if (objFBTwitterFeeds.TwitterFeed != null)
                            {
                                try
                                {
                                    objFBTwitterFeeds.TicketNo = item.TicketNo;
                                    if (user != null)
                                    {
                                        objFBTwitterFeeds.AssignedUser = user.UserName;
                                    }
                                    else
                                    {
                                        objFBTwitterFeeds.AssignedUser = "";
                                    }
                                    objListFBTwitterFeeds.Add(objFBTwitterFeeds);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                            if (objFBTwitterFeeds.FacebookFeed != null)
                            {
                                try
                                {
                                    objFBTwitterFeeds.TicketNo = item.TicketNo;
                                    if (user != null)
                                    {
                                        objFBTwitterFeeds.AssignedUser = user.UserName;
                                    }
                                    else
                                    {
                                        objFBTwitterFeeds.AssignedUser = "";
                                    }
                                    objListFBTwitterFeeds.Add(objFBTwitterFeeds);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                        }
                    } 
                }
               
                return new JavaScriptSerializer().Serialize(objListFBTwitterFeeds);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return "SomethingWentWrong";
            }

        }
        public bool GrpMem(Domain.Socioboard.Domain.User user) 
        {
            GroupsRepository grpRep = new GroupsRepository();
            GroupMembersRepository grpMemRep = new GroupMembersRepository();
            UserRepository userRepo = new UserRepository();
           // Domain.Socioboard.Domain.User user = userRepo.getUserInfoByEmail(Email);
            //foreach (var user in lstUser) 
            //{
                try 
                {
                    List<Domain.Socioboard.Domain.Groups> lstGroups = grpRep.getAlluserGroups(user.Id);
                    foreach (var item in lstGroups)
                    {
                        try
                        {
                            if (user != null)
                            {
                                Domain.Socioboard.Domain.Groupmembers grpMember = new Domain.Socioboard.Domain.Groupmembers();
                                grpMember.Id = Guid.NewGuid();
                                grpMember.Emailid = user.EmailId;
                                grpMember.Groupid = item.Id.ToString();
                                grpMember.IsAdmin = true;
                                grpMember.Status = Domain.Socioboard.Domain.GroupUserStatus.Accepted;
                                grpMember.Userid = item.UserId.ToString();
                                if (!grpMemRep.checkMemberExistsingroup(grpMember.Groupid, grpMember.Userid))
                                {
                                    grpMemRep.AddGroupMemeber(grpMember);
                                }

                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                            logger.Error(ex.StackTrace);
                        }


                    }
                }
                catch (Exception e) { }
               

            //}
            
            return true;

        }
        public IHttpActionResult GrpMemService() 
        {
            UserRepository userRepo = new UserRepository();
            List<Domain.Socioboard.Domain.User> lstUser = userRepo.getAllUsers();
            foreach (var user in lstUser) 
            {
                try 
                {
                    GrpMem(user);
                }
                catch { }
            }
            return Ok();


        }