public HttpResponseMessage SendRecurringNotification()
        {
            ListOfInvitedFriendResponse result = new ListOfInvitedFriendResponse();

            try
            {
                var    headers = Request.Headers;
                string token   = headers.Authorization.Parameter.ToString();
                Int64  UserId  = _objFriendFitDBEntity.Database.SqlQuery <Int64>("select UserId from UserToken where TokenCode={0}", token).FirstOrDefault();

                //result.Response.listofFriends = _objIFriendInvitationRepository.ListOfInvitedFriend(UserId);
                List <ListOfInvitedFriends> obj = new List <ListOfInvitedFriends>();

                obj = _objFriendFitDBEntity.Database.SqlQuery <ListOfInvitedFriends>("SendRecurringNotification @UserId=@UserId",
                                                                                     new SqlParameter("UserId", UserId)).ToList();


                result.Response.listofFriends = _objFriendFitDBEntity.Database.SqlQuery <ListOfInvitedFriends>("SendRecurringNotification @UserId=@UserId",
                                                                                                               new SqlParameter("UserId", UserId)).ToList();

                #region Send a mail Recuring
                foreach (var item in obj)
                {
                    var      email = item.Email;
                    DateTime d1    = Convert.ToDateTime(item.ExpiryDate);
                    DateTime d2    = DateTime.Now;

                    TimeSpan t        = d1 - d2;
                    double   NrOfDays = t.TotalDays;
                    int      ndays    = Convert.ToInt32(NrOfDays);
                    if (ndays <= -6 || ndays <= -5 || ndays <= -4 || ndays <= -3 || ndays <= -2 || ndays <= -1)
                    {
                        if (item.Email != null)
                        {
                            // update recursive flag
                            int value = _objFriendFitDBEntity.Database.ExecuteSqlCommand("update FriendsInvitation set RecFlag='RF' where Email='" + item.Email + "' and FriendsName='" + item.FriendsName + "'");
                            //
                            string RegistrationUrl = WebConfigurationManager.AppSettings["FrendFitSignUp"];
                            var    SendingMessage  = new MailMessage();
                            SendingMessage.To.Add(new MailAddress(item.Email));
                            SendingMessage.From    = new MailAddress("*****@*****.**");
                            SendingMessage.Subject = "Recuring Notification email (noti.fit)";
                            //SendingMessage.Body = "<p>Hi [FirstNameOfNewFriend]</p>< p >Your friend[FirstNameOfExistingUser] has invited you to track their workouts on noti.fit!noti.fit is a workout tracker that sends you notifications when your friend misses a workout.</ p >< p > Please sign up at[link] to get started!</ p >< p > Cheers<strong>,</ strong >< br /> The noti.fit tea</ p > ";
                            SendingMessage.Body       = " <p><strong> Hi " + item.Email + "</ strong >  ,<br/>Recurring : Recurring payment to be due " + item.ExpiryDate + " of this date,<br/><br/><strong>Please visit</strong> <br/><br/>Kind regards,<br/>The noti.fit team";
                            SendingMessage.IsBodyHtml = true;

                            using (var smtp = new SmtpClient())
                            {
                                var credential = new NetworkCredential
                                {
                                    UserName = "******",
                                    Password = "******"
                                };
                                smtp.Credentials = credential;
                                smtp.Host        = "smtp.gmail.com";
                                smtp.Port        = 587;
                                smtp.EnableSsl   = true;
                                smtp.Send(SendingMessage);
                            }
                        }
                    }
                }
                #endregion

                if (result.Response.listofFriends.Count > 0)
                {
                    result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                    result.Response.Message    = "Success!";
                }
                else
                {
                    result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotFound);
                    result.Response.Message    = "No Records";
                }
            }
            catch (Exception ex)
            {
                result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest);
                _response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Some error occurred");
            }
            _response = Request.CreateResponse(HttpStatusCode.OK, result);
            return(_response);
        }
        public HttpResponseMessage ListOfInvitedFriend()
        {
            ListOfInvitedFriendResponse result = new ListOfInvitedFriendResponse();

            try
            {
                var    headers = Request.Headers;
                string token   = headers.Authorization.Parameter.ToString();
                Int64  UserId  = _objFriendFitDBEntity.Database.SqlQuery <Int64>("select UserId from UserToken where TokenCode={0}", token).FirstOrDefault();

                //result.Response.listofFriends = _objIFriendInvitationRepository.ListOfInvitedFriend(UserId);
                List <ListOfInvitedFriends> obj = new List <ListOfInvitedFriends>();

                obj = _objFriendFitDBEntity.Database.SqlQuery <ListOfInvitedFriends>("ListOfFriends @UserId=@UserId",
                                                                                     new SqlParameter("UserId", UserId)).ToList();

                var _ListOfInvitedFriends = _objFriendFitDBEntity.Database.SqlQuery <ListOfInvitedFriends>("ListOfFriends @UserId=@UserId",
                                                                                                           new SqlParameter("UserId", UserId)).Where(s => s.PaymentDone == 0).ToList();

                foreach (var item in _ListOfInvitedFriends)
                {
                    DateTime dt_CurrentDate  = DateTime.Today.Date;
                    DateTime dt_PurchaseDate = Convert.ToDateTime(item.PurchaseDate).Date;
                    DateTime dt_ExpiryDate   = Convert.ToDateTime(item.ExpiryDate).Date;
                    DateTime New_dt_PurchaseDate;
                    DateTime New_dt_ExpiryDate;

                    if (dt_PurchaseDate < dt_CurrentDate)
                    {
                        double TotalDayDiff = (dt_CurrentDate - dt_PurchaseDate).TotalDays;
                        New_dt_PurchaseDate = Convert.ToDateTime(item.PurchaseDate).Date.AddDays(TotalDayDiff);
                        New_dt_ExpiryDate   = Convert.ToDateTime(item.ExpiryDate).Date.AddDays(TotalDayDiff);

                        var UpdateFriendsInvitations = _objFriendFitDBEntity.FriendsInvitations.Where(x => x.Id == item.FriendId).FirstOrDefault();
                        UpdateFriendsInvitations.PurchaseDate = New_dt_PurchaseDate;
                        UpdateFriendsInvitations.ExpiryDate   = New_dt_ExpiryDate;
                        _objFriendFitDBEntity.Entry(UpdateFriendsInvitations).State = System.Data.Entity.EntityState.Modified;
                        _objFriendFitDBEntity.SaveChanges();
                    }
                }

                result.Response.listofFriends = _objFriendFitDBEntity.Database.SqlQuery <ListOfInvitedFriends>("ListOfFriends @UserId=@UserId",
                                                                                                               new SqlParameter("UserId", UserId)).ToList();

                if (result.Response.listofFriends.Count > 0)
                {
                    result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                    result.Response.Message    = "Success!";
                }
                else
                {
                    result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotFound);
                    result.Response.Message    = "No Records";
                }
            }
            catch (Exception ex)
            {
                result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest);
                _response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Some error occurred");
            }
            _response = Request.CreateResponse(HttpStatusCode.OK, result);
            return(_response);
        }