public string AddAssociate(Cog.MLIAD.BusinessLogic.Associate.Associate associate)
        {
            using (AssociateConnDataContext asscon = new AssociateConnDataContext())
            {
                try
                {
                    int retasct = 0;
                    retasct = asscon.Add_Associate(associate.AssociateID, associate.FirstName, associate.LastName, associate.Mobile, associate.email, associate.DirectReportID, associate.IsApproved, associate.ProjectID, associate.LocationID, associate.DesignationID, associate.DOJ, associate.DOB, associate.IsActive, associate.UserID, associate.Password, associate.GroupID);
                    if (!(retasct == 0))
                    {
                        BusinessLogic.Associate.Associate approver = (from a in asscon.get_AdminByGroup(associate.GroupID)
                                                                      select new Cog.MLIAD.BusinessLogic.Associate.Associate()
                                                                      {
                                                                          AssociateID = a.AssociateID,
                                                                          FirstName = (a.FirstName == null) ? "" : a.FirstName,
                                                                          LastName = (a.LastName == null) ? "" : a.LastName,
                                                                          Mobile = (a.Mobile == null) ? "" : a.Mobile,
                                                                          email = (a.email == null) ? "" : a.email,
                                                                          UserID = (a.UserId == null) ? "" : a.UserId
                                                                      }).SingleOrDefault<Cog.MLIAD.BusinessLogic.Associate.Associate>();

                        string sendSubject = "Pending Request";
                        string mailbody = "<html><body>Dear " + approver.FirstName + ",<br /> You have pending request to approve for " + associate.FirstName + " " + associate.LastName + ".<br / >Please login to www.AssociateConnect.com to approve the request.<br / ><br />Regards,<br />AssociateConnect Admin Team<body><html>";
                        SendEmail(sendSubject, mailbody, associate.email, approver.email,true);
                        sendSubject = "Request Summited";
                        mailbody = "<html><body>Dear " + associate.FirstName + ",<br /> your request is successfully submitted to" + approver.FirstName + " " + approver.LastName + " for approval.<br / >You will get confirmation mail once your request gets appreved.<br / ><br />Regards,<br />AssociateConnect Admin Team<body><html>";
                        SendEmail(sendSubject, mailbody, approver.email, associate.email,true);

                        BusinessLogic.Associate.SMS sms = new SMS();
                        sms.smsBody = "You have pending request to approve for " + associate.FirstName + " " + associate.LastName + ".";
                        sms.toList = approver.Mobile;
                        SendSMS(sms);
                        sms.smsBody = "your request is successfully submitted to" + approver.FirstName + " " + approver.LastName + " for approval.";
                        sms.toList = associate.Mobile;
                        SendSMS(sms);

                        return "success";
                    }
                    else
                        return "failure";
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
        public string AddAddress(Associate.Address address, string AssociateID)
        {
            using (AssociateConnDataContext asscon = new AssociateConnDataContext())
            {
                try
                {
                    int retadd = 0;
                    int AssoID = Convert.ToInt32(AssociateID);
                    retadd = asscon.Add_Address(AssoID, address.AddressTypeID, address.Address1, address.Address2, address.Address3, address.City, address.State, address.Country, address.Zip);
                    if (!(retadd == 0))
                        return "success";
                    else
                        return "failure";
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
        public List<Associate.Discussion> GetTopics(int CategoryID, int groupID)
        {
            try
            {

                using (AssociateConnDataContext asso = new AssociateConnDataContext())
                {
                    var discussions = (from d in asso.Get_Topics(CategoryID, groupID)
                                       orderby d.PostDateTime descending
                                       where d.IsParent == true
                                       select new Associate.Discussion
                                      {
                                          TopicDesc = d.TopicDesc,
                                          TopicHeader = d.topicheader,
                                          TopicID = d.TopicID,
                                          PostDateTime = d.PostDateTime,
                                          IsParent = d.IsParent,
                                          CreatedBy = d.CreatedBy,
                                          CreatedByname=d.FirstName + " " + d.LastName ,
                                          CommentCount = d.CommentCount,
                                          Category = new Category { CategoryID = d.CategoryID, IsActive = d.IsActive, CategoryDesc = d.CategoryDesc },
                                          Group = new Group { GroupID = d.GroupID, GroupDesc = d.GroupDesc },

                                      });
                    List<Associate.Discussion> diss = new List<Associate.Discussion>(discussions);
                    return diss;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public string AddCategory(Cog.MLIAD.BusinessLogic.Associate.Category category)
        {
            using (AssociateConnDataContext asscon = new AssociateConnDataContext())
            {
                try
                {
                    int retasct = 0;
                    retasct = asscon.Add_Category(category.CategoryDesc, category.IsActive);
                    if (!(retasct == 0))
                        return "success";
                    else
                        return "failure";
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
 public List<Associate.SoftwareVersion> GetSoftwareVersion(int softResourceID)
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var resources = (from a in asscon.Get_SoftwareVersion(softResourceID)
                          select new Associate.SoftwareVersion()
                          {
                              SoftwareVersionID = a.SoftVersionID,
                              SoftwareVersionDesc = a.SoftVersionDesc
                          }).ToList<Associate.SoftwareVersion>();
         return resources;
     }
 }
 public List<Associate.SoftwareCategory> GetSoftwareCategory()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var categories = (from a in asscon.Get_SoftwareCategory()
                           select new Associate.SoftwareCategory()
                           {
                               SoftwareCategoryID = a.SoftCategoryID,
                               SoftwareCategoryDesc = a.SoftCategoryDesc
                           }).ToList<Associate.SoftwareCategory>();
         return categories;
     }
 }
 public List<Associate.Project> GetProject()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var projects = (from a in asscon.Get_Project()
                         select new Associate.Project()
                         {
                             ProjectID = a.ProjectID,
                             ProjectName = a.ProjectName
                         }).ToList<Associate.Project>();
         return projects;
     }
 }
 public List<Associate.PhoneType> GetPhoneType()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var types = (from a in asscon.Get_PhoneType()
                      select new Associate.PhoneType()
                      {
                          PhoneTypeID = Convert.ToInt32(a.PhoneTypeID),
                          PhoneTypeDesc = a.PhoneType
                      }).ToList<Associate.PhoneType>();
         return types;
     }
 }
 public List<Associate.Associate> GetApprovalRequest()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var ids = (from a in asscon.Get_ApprovalRequest()
                    select new Associate.Associate()
                    {
                        AssociateID = a.AssociateID
                    }).ToList<Associate.Associate>();
         return ids;
     }
 }
        public List<SMSAccount> GetAllAccounts()
        {
            List<SMSAccount> acc = new List<SMSAccount>();
            using (AssociateConnDataContext asscon = new AssociateConnDataContext())
            {
                var associate = (from a in asscon.sp_SMSAccounts("SELECT",null,null,null,null,null)

                                 select new SMSAccount()
                                 {
                                     id=a.Id,
                                     password=a.Password,
                                     phoneNumber=a.Phone,
                                     sentSMS=a.SentSMS,
                                     email=a.Email
                                 }).ToList<SMSAccount>();
                acc = associate;
                return acc;
            }
        }
 public List<Associate.AddressType> GetAddressType()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var types = (from a in asscon.Get_AddressType()
                      select new Associate.AddressType()
                      {
                          AddressTypeID = a.AddressTypeID,
                          AddressTypeDesc = a.AddressType
                      }).ToList<Associate.AddressType>();
         return types;
     }
 }
 public List<Associate.Account> GetAccount(int PracticeID)
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var accounts = (from a in asscon.Get_Account(PracticeID)
                         select new Associate.Account()
                         {
                             AccountID = a.AccountID,
                             AccountName = a.AccountName
                         }).ToList<Associate.Account>();
         return accounts;
     }
 }
        public Associate.Associate ForgotPassword(string userid, int associateid, string name)
        {
            try
                {
                    using (AssociateConnDataContext asscon = new AssociateConnDataContext())
                    {
                        var Associate = (from a in asscon.GetUserPWD(userid, associateid, name)
                                         select new Associate.Associate()
                                         {
                                             email = a.email,
                                             Mobile = a.Mobile,
                                             Password = a.Password,

                                         }).SingleOrDefault();

                        return Associate;
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
        }
 public string EditSoftware(Associate.SoftwareRequest software)
 {
     int SoftRequestID = Convert.ToInt32(software.id);
     int SoftCategoryID = Convert.ToInt32(software.SoftCategory);
     int SoftResourceID = Convert.ToInt32(software.SoftResource);
     int SoftVersionID = Convert.ToInt32(software.SoftVersion);
     int ProjectID = Convert.ToInt32(software.ProjectName);
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         try
         {
             int retval = asscon.Edit_Software(SoftRequestID, SoftResourceID, SoftCategoryID, SoftVersionID, ProjectID);
             if (retval == 1)
                 return "sucess";
             else
                 return "failure";
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
        public string EditFirewall(Associate.FirewallRequest firewall)
        {
            int RequestedID = Convert.ToInt32(firewall.id);
            int ProjectID = Convert.ToInt32(firewall.ProjectName);
            using (AssociateConnDataContext asscon = new AssociateConnDataContext())
            {
                try
                {
                    int retval = asscon.Edit_Firewall(RequestedID, firewall.FirewallRequestDesc, firewall.Destination, firewall.Source, firewall.Port, ProjectID);
                    if (retval == 1)
                        return "sucess";
                    else
                        return "failure";
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
        }
 public List<Associate.Group> GetGroupsByUser(int uid)
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var groups = (from a in asscon.Get_GroupByID(uid)
                       select new Associate.Group()
                       {
                           GroupID = a.GroupID,
                           GroupDesc = a.GroupName
                       }).ToList<Associate.Group>();
         return groups;
     }
 }
 public List<Associate.Location> GetLocation()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var locations = (from a in asscon.Get_Location()
                          select new Associate.Location()
                          {
                              LocationID = a.LocationID,
                              LocationName = a.Location
                          }).ToList<Associate.Location>();
         return locations;
     }
 }
        public Associate.Associate GetAssociate(string userid)
        {
            using (AssociateConnDataContext asscon = new AssociateConnDataContext())
            {
                var associate = (from a in asscon.Associates
                                 where a.UserId == userid
                                 select new Associate.Associate()
                              {
                                  AssociateID = a.AssociateID ,
                                  DesignationID = a.DesignationID ,
                                  DirectReportID =a.DirectReportID ,
                                  DOB =a.DOB ,
                                  DOJ =a.DOJ ,
                                  email =a.email ,
                                  FirstName =a.FirstName ,
                                  LastName =a.LastName ,
                                  LocationID =a.LocationID ,
                                  Mobile =a.Mobile

                              }).SingleOrDefault<Associate.Associate>();
                return  associate;
            }
        }
 public List<Associate.Practice> GetPractice()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var practices = (from a in asscon.Get_Practice()
                          select new Associate.Practice()
                          {
                              PracticeID = a.PracticeID,
                              PracticeName = a.PracticeName
                          }).ToList<Associate.Practice>();
         return practices;
     }
 }
 public Associate.Associate GetAssociateByID(string AssociateID)
 {
     int id = (AssociateID == string.Empty) ? 0 : Convert.ToInt32(AssociateID);
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var associates = (from a in asscon.Get_AssociateByID(id)
                           select new Associate.Associate()
                           {
                               AssociateID = a.AssociateID,
                               FirstName = a.FirstName,
                               LastName = a.LastName,
                               Designation = a.Designation,
                               Practice = a.PracticeName,
                               Account = a.AccountName,
                               Location = a.Location,
                               email = a.email,
                               Mobile = a.Mobile,
                               DOJ = a.DOJ,
                               ProjectName = a.ProjectName,
                               Gender = a.Gender
                           }).SingleOrDefault<Associate.Associate>();
         return associates;
     }
 }
 public List<Associate.Role> GetRole()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var roles = (from a in asscon.Get_Role()
                      select new Associate.Role()
                      {
                          RoleID = a.RoleID,
                          RoleDesc = a.RoleDesc
                      }).ToList<Associate.Role>();
         return roles;
     }
 }
        public BusinessLogic.Associate.Associate GetAssociatesByUserID(string UserID)
        {
            try
            {

                using (AssociateConnDataContext asso = new AssociateConnDataContext())
                {
                    var associate = (from d in asso.Get_AssociateByUserID(UserID)
                                     select new Associate.Associate
                                     {
                                         AssociateID = d.AssociateID,
                                         FirstName = d.FirstName,
                                         LastName = d.LastName
                                     }).SingleOrDefault<Associate.Associate>();

                    return associate;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public List<Associate.SoftwareResource> GetSoftwareResource(int softCategoryID)
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var resources = (from a in asscon.Get_SoftwareResource(softCategoryID)
                          select new Associate.SoftwareResource()
                          {
                              SoftwareResourceID = a.SoftResourceID,
                              SoftwareResourceDesc = a.SoftResourceDesc
                          }).ToList<Associate.SoftwareResource>();
         return resources;
     }
 }
        public List<BusinessLogic.Associate.Associate> GetAssociatesPerGroup(int groupid)
        {
            try
            {

                using (AssociateConnDataContext asso = new AssociateConnDataContext())
                {
                    var assoList = (from d in asso.Get_AssoListPerGroup(groupid)
                                    select new Associate.Associate
                                    {
                                        AssociateID = d.AssociateID,
                                        FirstName = d.FirstName,
                                        LastName = d.LastName,
                                        email = d.email,
                                        Mobile = d.Mobile
                                    }).ToList<Associate.Associate>();

                    return assoList;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public Associate.Discussion GetTopic(int topicID)
        {
            try
            {

                using (AssociateConnDataContext asso = new AssociateConnDataContext())
                {
                    var discussion = (from d in asso.Get_Topic(topicID)
                                       orderby d.PostDateTime descending
                                       where d.TopicID == topicID
                                       select new Associate.Discussion
                                       {
                                           TopicDesc = d.TopicDesc,
                                           TopicHeader = d.topicheader,
                                           TopicID = d.TopicID,
                                           PostDateTime = d.PostDateTime,
                                           IsParent = d.IsParent,
                                           CreatedBy = d.CreatedBy,
                                           CreatedByname = d.FirstName + " " + d.LastName,
                                           CommentCount = d.CommentCount,
                                           Category = new Category { CategoryID = d.CategoryID, CategoryDesc = d.CategoryDesc },
                                           Group = new Group { GroupID = d.GroupID, GroupDesc = d.GroupDesc },

                                       }).SingleOrDefault();

                    return discussion;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<BusinessLogic.Associate.Associate> GetAssociatesPerGroupAndRole(int groupid, int roleid)
        {
            try
            {

                using (AssociateConnDataContext asso = new AssociateConnDataContext())
                {
                    var assoList = (from d in asso.GetMemberByGroupAndRole(groupid, roleid)
                                    select new Associate.Associate
                                    {
                                        AssociateID = d.AssociateID,
                                        FirstName = d.FirstName,
                                        LastName = d.LastName
                                    }).ToList<Associate.Associate>();
                    return assoList;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<Associate.DiscussionDetails> GetTopicDetails(int topicID)
        {
            try
            {

                using (AssociateConnDataContext asso = new AssociateConnDataContext())
                {
                    var dissDetails = (from d in asso.Get_TopicDetails(topicID)
                                       orderby d.CreatedOn descending
                                       select new Associate.DiscussionDetails
                                       {
                                           TopicDetailID = d.DiscussionDetailID,
                                           DetailDesc = d.DetailDesc,
                                           CreatedOn = d.CreatedOn,
                                           CreatedBy = d.CreatedBy,
                                           CreatedByname = d.CreatedByName,
                                           ParentID = topicID,

                                       }).ToList<Associate.DiscussionDetails>();

                    return dissDetails;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public List<Associate.Category> GetCategories()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var groups = (from a in asscon.Get_Category()
                       select new Associate.Category()
                       {
                           CategoryID = a.CategoryID,
                           CategoryDesc = a.CategoryDesc
                       }).ToList<Associate.Category>();
         return groups;
     }
 }
        public Associate.Associate LoginUser(string userid, string pwd)
        {
            try
                {
                    using (AssociateConnDataContext asscon = new AssociateConnDataContext())
                    {
                        var Associate = (from a in asscon.getAthenticateUser(userid, pwd)
                                           select new Associate.Associate()
                                           {
                                               AssociateID=a.AssociateID,
                                               //Designation = a.Designation,
                                               //DesignationID = a.DesignationID ,
                                               //DirectReportID = a.DirectReportID,
                                               //DirectReporter = a.DirectReporter,
                                               //DOB = a.DOB,
                                               //DOJ = a.DOJ,
                                               email=a.email,
                                               Gender=a.Gender,
                                               //Location = a.Location,
                                               //LocationID = a.LocationID,
                                               Mobile = a.Mobile,
                                               Name=a.Name,
                                               //ProjectID=a.ProjectID.Value,
                                               //ProjectName=a.ProjectName,
                                               IsApproved=a.IsApproved
                                           }).SingleOrDefault();

                        Associate.groupList = (from b in asscon.getAssociateRoleGroup(userid)
                                               select new Associate.Group()
                                               {
                                                   GroupDesc = b.GroupDesc,
                                                   GroupName=b.GroupName,
                                                   GroupID = b.GroupID.Value
                                               }).ToList<Associate.Group>();

                        Associate.Role = (from b in asscon.getAssociateRoleGroup(userid)
                                          select new Associate.Role()
                                          {
                                              RoleDesc = b.RoleDesc,
                                              RoleID = b.RoleID.Value
                                          }).FirstOrDefault();

                        if (Associate.groupList.Count > 0)
                        {
                            return Associate;
                        }
                        else
                        {
                            throw new Exception("No group available for the user");
                            //return null;
                        }
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
        }
 public List<Associate.Designation> GetDesignation()
 {
     using (AssociateConnDataContext asscon = new AssociateConnDataContext())
     {
         var designations = (from a in asscon.Get_Designation()
                             select new Associate.Designation()
                             {
                                 DesignationID = a.DesignationID,
                                 DesignationName = a.Designation
                             }).ToList<Associate.Designation>();
         return designations;
     }
 }