//Create group
        public static int Create(GroupDTO GroupDTO)
        {
            try
            {

                GlobalSettings.LoggedInClientId = GroupDTO.ClientID;
                int PartnerId = ClientService.GetById(GroupDTO.ClientID).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var group = new Group();

                UnitOfWork uow = new UnitOfWork();
                GroupDTO.ClientID = GroupDTO.ClientID;
                group = Transform.GroupToDomain(GroupDTO);
                uow.GroupRepo.Insert(group);

                uow.SaveChanges();

                GroupDTO.Id = group.Id;
                return GroupDTO.Id;

            }

            catch (Exception)
            {
                throw;
            }
        }
        public static int GetGroupIdWisePresentContactsCountByClientId(int ClientId, int GroupId, string Search)
        {
            List<ContactDTO> contactDTOList = new List<ContactDTO>();
            List<ContactDTO> contactDTO = new List<ContactDTO>();
            try
            {

                UnitOfWork uow = new UnitOfWork();
                Group Group = new Group();
                Group = uow.GroupRepo.GetById(GroupId); //, true
                List<ContactDTO> Contact = GroupContactService.GetGroupIdWiseContacts(Group.Id);// Group.Contacts; //Contact

                if (Contact != null)
                {
                    if (Search != "" && Search != null)
                    {
                        bool IsDate = CommonService.IsDate(Search);
                        if (IsDate != true)
                        {
                            List<ContactDTO> Contactsearch = Contact.Where(e => (e.Email != null ? (e.Email.ToLower().Contains(Search.ToLower())) : false) || e.MobileNumber.Contains(Search) || (e.Name != null ? (e.Name.ToLower().Contains(Search.ToLower())) : false) || (e.FirstName != null ? (e.FirstName.ToLower().Contains(Search.ToLower())) : false) || (e.LastName != null ? (e.LastName.ToLower().Contains(Search.ToLower())) : false) || (e.AnniversaryDate.ToString() != null ? (Convert.ToDateTime(e.AnniversaryDate).ToString("dd-MMM-yyyy").ToLower().Contains(Search.ToLower())) : false) || (e.BirthDate.ToString() != null ? (Convert.ToDateTime(e.BirthDate).ToString("dd-MMM-yyyy").ToLower().Contains(Search.ToLower())) : false)).ToList(); //.OrderBy(e => e.Name)
                            //Group.Contacts
                            if (Contactsearch != null)
                            {
                                return Contactsearch.Count();
                            }
                        }
                        else
                        {
                            DateTime date = Convert.ToDateTime(Search);
                            List<ContactDTO> Contactsearch = Contact.Where(e => e.AnniversaryDate >= date && e.AnniversaryDate < date.AddDays(1) || e.BirthDate >= date && e.BirthDate < date.AddDays(1)).ToList();//.OrderBy(e => e.Name);
                            //Group.Contacts
                            if (Contactsearch != null)
                            {
                                return Contactsearch.Count();
                            }
                        }
                    }
                    return Contact.Count();
                }
                return Contact.Count();

                ////var contacts = from c in Contact  where ( from g in c.Groups where g.Id ==GroupId select g ).Any() select c;
                //GroupContactDTO GroupContactDTO = GroupService.GetGroupContactById(GroupId);// uow.GroupRepo.GetAll().Where(e => e.ClientID == ClientId).ToList();
                //List<ContactDTO> ContactDTO = GroupContactDTO.Contacts;
                //contactDTOList= ContactDTO;

                // if (contactDTOList != null)
                //  {

                //      if (Search != "" && Search != null)
                //      {

                //          bool IsDate = CommonService.IsDate(Search);
                //          if (IsDate != true)
                //          {
                //              // string search

                //              var Contactsearch = contactDTOList.Where(e => (e.Email != null ? (e.Email.ToLower().Contains(Search.ToLower())) : false) || e.MobileNumber.Contains(Search) || (e.Name != null ? (e.Name.ToLower().Contains(Search.ToLower())) : false) || (e.FirstName != null ? (e.FirstName.ToLower().Contains(Search.ToLower())) : false) || (e.LastName != null ? (e.LastName.ToLower().Contains(Search.ToLower())) : false) || (e.AnniversaryDate.ToString() != null ? (Convert.ToDateTime(e.AnniversaryDate).ToString("dd-MMM-yyyy").ToLower().Contains(Search.ToLower())) : false) || (e.BirthDate.ToString() != null ? (Convert.ToDateTime(e.BirthDate).ToString("dd-MMM-yyyy").ToLower().Contains(Search.ToLower())) : false)); //.OrderBy(e => e.Name)

                //              if (Contactsearch != null)
                //              {
                //                  foreach (var item in Contactsearch)
                //                  {
                //                      ContactDTO ContactDTOObj = new ContactDTO();
                //                      contactDTO.Add(item);
                //                  }

                //              } return contactDTO.Count();

                //          }
                //          else
                //          {
                //              //date wise search
                //              DateTime date = Convert.ToDateTime(Search);
                //              var Contactsearch = contactDTOList.Where(e => e.AnniversaryDate >= date && e.AnniversaryDate < date.AddDays(1) || e.BirthDate >= date && e.BirthDate < date.AddDays(1));//.OrderBy(e => e.Name);

                //              if (Contactsearch != null)
                //              {
                //                  foreach (var item in Contactsearch)
                //                  {
                //                      ContactDTO ContactDTOObj = new ContactDTO();
                //                      contactDTO.Add(item);
                //                  }
                //              }
                //              return contactDTO.Count();
                //          }
                //      }
                //  }
                //  return contactDTOList.Count();
            }
            catch (Exception)
            {

                throw;
            }
        }
        public static List<ContactDTO> GetGroupIdWisePresentContactsByClientId(int ClientId, int GroupId, PagingInfo pagingInfo)
        {
            List<ContactDTO> contactDTOList = new List<ContactDTO>();
            List<ContactDTO> contactDTO = new List<ContactDTO>();
            try
            {
                UnitOfWork uow = new UnitOfWork();
                int skip = (pagingInfo.Page - 1) * pagingInfo.ItemsPerPage;
                int take = pagingInfo.ItemsPerPage;
                //IEnumerable<Contact> Contact = uow.ContactRepo.GetAll().Where(e => e.ClientId == ClientId).ToList();
                //var contacts = from c in Contact  where ( from g in c.Groups where g.Id ==GroupId select g ).Any() select c;

                Group Group = new Group();
                Group = uow.GroupRepo.GetById(GroupId); //, true
                IQueryable<ContactDTO> Contact = GroupContactService.GetGroupIdWiseContacts(Group.Id).AsQueryable();// Group.Contacts.AsQueryable();
                Contact = PagingService.Sorting<ContactDTO>(Contact, pagingInfo.SortBy, pagingInfo.Reverse);
                //Contact = Contact.Skip(skip).Take(take);
                if (Contact != null)
                {
                    foreach (var item in Contact)
                    {
                        ContactDTO ContactDTOobj = new ContactDTO();
                        ContactDTOobj = item;// Transform.ContactToDTO(item);
                        contactDTOList.Add(ContactDTOobj);
                    }

                    if (pagingInfo.Search != "" && pagingInfo.Search != null)
                    {
                        bool IsDate = CommonService.IsDate(pagingInfo.Search);
                        if (IsDate != true)
                        {
                            IQueryable<ContactDTO> Contactsearch = Contact.Where(e => (e.Email != null ? (e.Email.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || e.MobileNumber.Contains(pagingInfo.Search) || (e.Name != null ? (e.Name.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.FirstName != null ? (e.FirstName.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.LastName != null ? (e.LastName.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.AnniversaryDate.ToString() != null ? (Convert.ToDateTime(e.AnniversaryDate).ToString("dd-MMM-yyyy").ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.BirthDate.ToString() != null ? (Convert.ToDateTime(e.BirthDate).ToString("dd-MMM-yyyy").ToLower().Contains(pagingInfo.Search.ToLower())) : false)).AsQueryable();
                            //Group.Contacts
                            Contactsearch = PagingService.Sorting<ContactDTO>(Contactsearch, pagingInfo.SortBy, pagingInfo.Reverse);
                            Contactsearch = Contactsearch.Skip(skip).Take(take);
                            foreach (var item in Contactsearch)
                            {
                                contactDTO.Add(item); //Transform.ContactToDTO(item)
                            }
                            return contactDTO;
                        }
                        else
                        {
                            DateTime date = Convert.ToDateTime(pagingInfo.Search);
                            IQueryable<ContactDTO> Contactsearch = Contact.Where(e => e.AnniversaryDate >= date && e.AnniversaryDate < date.AddDays(1) || e.BirthDate >= date && e.BirthDate < date.AddDays(1)).AsQueryable(); // .Skip(skip).Take(take); //.OrderBy(e => e.Name)
                            //Group.Contacts
                            Contactsearch = PagingService.Sorting<ContactDTO>(Contactsearch, pagingInfo.SortBy, pagingInfo.Reverse);
                            Contactsearch = Contact.Skip(skip).Take(take);
                            foreach (var item in Contactsearch)
                            {
                                contactDTO.Add(item); //Transform.ContactToDTO(item)
                            }
                            return contactDTO;
                        }
                    }
                    else

                        return contactDTOList.Skip(skip).Take(take).ToList();
                }
                else
                {
                    //foreach (var item in Contact)
                    //{
                    //    contactDTOList.Add(Transform.ContactToDTO(item));
                    //}
                    return contactDTOList.Skip(skip).Take(take).ToList();
                }

                //GroupContactDTO GroupContactDTO = GroupService.GetGroupContactById(pagingInfo.GroupId);// uow.GroupRepo.GetAll().Where(e => e.ClientID == ClientId).ToList();
                //IQueryable<ContactDTO> ContactDTO = GroupContactDTO.Contacts.AsQueryable();// .Skip(skip).Take(take).ToList();

                //ContactDTO = PagingService.Sorting<ContactDTO>(ContactDTO, pagingInfo.SortBy, pagingInfo.Reverse);
                //ContactDTO = ContactDTO.Skip(skip).Take(take);

                //if (ContactDTO != null)
                //{
                //    contactDTOList = ContactDTO.ToList() ;
                //    if (pagingInfo.Search != "" && pagingInfo.Search != null)
                //    {
                //        bool IsDate = CommonService.IsDate(pagingInfo.Search);
                //        if (IsDate != true)
                //        {
                //            // string search
                //            IQueryable<ContactDTO> Contactsearch = contactDTOList.Where(e => (e.Email != null ? (e.Email.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || e.MobileNumber.Contains(pagingInfo.Search) || (e.Name != null ? (e.Name.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.FirstName != null ? (e.FirstName.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.LastName != null ? (e.LastName.ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.AnniversaryDate.ToString() != null ? (Convert.ToDateTime(e.AnniversaryDate).ToString("dd-MMM-yyyy").ToLower().Contains(pagingInfo.Search.ToLower())) : false) || (e.BirthDate.ToString() != null ? (Convert.ToDateTime(e.BirthDate).ToString("dd-MMM-yyyy").ToLower().Contains(pagingInfo.Search.ToLower())) : false)).AsQueryable();// .Skip(skip).Take(take); //.OrderBy(e => e.Name)
                //            Contactsearch = PagingService.Sorting<ContactDTO>(Contactsearch, pagingInfo.SortBy, pagingInfo.Reverse);
                //            Contactsearch = Contactsearch.Skip(skip).Take(take);

                //            if (Contactsearch != null)
                //            {
                //                foreach (var item in Contactsearch)
                //                {
                //                    ContactDTO ContactDTOObj = new ContactDTO();
                //                    contactDTO.Add(item);
                //                }
                //            } return contactDTO;

                //        }
                //        else
                //        {
                //            //date wise search
                //            DateTime date = Convert.ToDateTime(pagingInfo.Search);
                //            IQueryable<ContactDTO> Contactsearch = contactDTOList.Where(e => e.AnniversaryDate >= date && e.AnniversaryDate < date.AddDays(1) || e.BirthDate >= date && e.BirthDate < date.AddDays(1)).AsQueryable(); // .Skip(skip).Take(take); //.OrderBy(e => e.Name)
                //            Contactsearch = PagingService.Sorting<ContactDTO>(Contactsearch, pagingInfo.SortBy, pagingInfo.Reverse);
                //            Contactsearch = Contactsearch.Skip(skip).Take(take);
                //            if (Contactsearch != null)
                //            {
                //                foreach (var item in Contactsearch)
                //                {
                //                    ContactDTO ContactDTOObj = new ContactDTO();
                //                    contactDTO.Add(item);
                //                }
                //            }
                //            return contactDTO;
                //        }
                //    }
                //}
                //return contactDTOList ;
            }
            catch (Exception)
            {

                throw;
            }
        }
        //Get Client's Latest Activities
        public static List<ActivityLogDTO> GetClientLatestActivities(int ClientId, int Top)
        {
            List<ActivityLogDTO> ActivityLogDTOList = new List<ActivityLogDTO>();
            try
            {
                using (var uow = new UnitOfWork())
                {
                    // DateTime yesterdayDate = DateTime.Now.AddDays(-Top).Date;
                    //var LogList = uow.ActivityLogRepo.Get(c => c.Date > yesterdayDate).ToList();
                    var LogList = uow.ActivityLogRepo.GetAll().Where(e => e.ClientId == Convert.ToInt32(ClientId)).OrderByDescending(e => e.Id).ToList();
                    int i = 0;
                    int j = 0;
                    foreach (var log in LogList)
                    {
                        j = 0;
                        if (log.EntityType == "GroupContact" || log.EntityType == "CampaignLogXML" || log.EntityType == "CampaignLog" || log.EntityType == "Coupon")
                        {
                            continue;
                        }

                        if (log.EntityType == "Campaign") //&& log.OperationType == "Added" || log.OperationType == "Modified"
                        {
                            Campaign Campaign = new Campaign();
                            Campaign = uow.CampaignRepo.GetById(log.EntityId);
                            if (Campaign != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = Campaign.Name;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;

                            }
                        }

                        if (log.EntityType == "Client") //&& log.OperationType == "Added" || log.OperationType == "Modified"
                        {
                            Client Client = new Client();
                            Client = uow.ClientRepo.GetById(log.EntityId);
                            if (Client != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = Client.Company;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;

                            }
                        }

                        if (log.EntityType == "Contact") //&& log.OperationType == "Added" || log.OperationType == "Modified"
                        {
                            Contact Contact = new Contact();
                            Contact = uow.ContactRepo.GetById(log.EntityId);
                            if (Contact != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = Contact.Name;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;

                            }
                        }

                        if (log.EntityType == "CreditRequest") //&& log.OperationType == "Added" || log.OperationType == "Modified"
                        {
                            CreditRequest CreditRequest = new CreditRequest();
                            CreditRequest = uow.CreditRequestRepo.GetById(log.EntityId);
                            if (CreditRequest != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = "";// "Credit Request";// uow.CreditRequestRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;

                            }
                        }

                        if (log.EntityType == "Document")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            Document Document = new Document();
                            Document = uow.DocumentRepo.GetById(log.EntityId);
                            if (Document != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = Document.FileName;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;

                            }
                        }

                        if (log.EntityType == "EcouponCampaign")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            EcouponCampaign EcouponCampaign = new EcouponCampaign();
                            EcouponCampaign = uow.EcouponCampaignRepo.GetById(log.EntityId);
                            if (EcouponCampaign != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = EcouponCampaign.Title;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;

                            }
                        }

                        if (log.EntityType == "Group")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            Group Group = new Group();
                            Group = uow.GroupRepo.GetById(log.EntityId);
                            if (Group != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = Group.Name;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;

                            }
                        }

                        //if (log.EntityType == "Partner")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        //{
                        //    Partner Partner = new Partner();
                        //    Partner = uow.PartnerRepo.GetById(log.EntityId);
                        //    if (Partner != null)
                        //    {
                        //        ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                        //        if (log.UserId != null)
                        //        {
                        //            ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                        //        }

                        //        if (log.PartnerId != null)
                        //        {
                        //            ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                        //        }

                        //        if (log.ClientId != null)
                        //        {
                        //            ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                        //        }

                        //        ActivityLogDTO.EntityName = Partner.Name;
                        //        ActivityLogDTO.Date = log.Date;
                        //        ActivityLogDTO.EntityType = log.EntityType;
                        //        ActivityLogDTO.OperationType = log.OperationType;
                        //        ActivityLogDTO.Id = log.Id;
                        //        ActivityLogDTOList.Add(ActivityLogDTO);
                        //        j = 1;
                        //    }
                        //}

                        //if (log.EntityType == "Plan")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        //{
                        //    Plan Plan = new Plan();
                        //    Plan = uow.PlanRepo.GetById(log.EntityId);
                        //    if (Plan != null)
                        //    {
                        //        ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                        //        if (log.UserId != null)
                        //        {
                        //            ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                        //        }

                        //        if (log.PartnerId != null)
                        //        {
                        //            ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                        //        }

                        //        if (log.ClientId != null)
                        //        {
                        //            ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                        //        }

                        //        ActivityLogDTO.EntityName = Plan.Title;
                        //        ActivityLogDTO.Date = log.Date;
                        //        ActivityLogDTO.EntityType = log.EntityType;
                        //        ActivityLogDTO.OperationType = log.OperationType;
                        //        ActivityLogDTO.Id = log.Id;
                        //        ActivityLogDTOList.Add(ActivityLogDTO);
                        //        j = 1;
                        //    }
                        //}

                        if (log.EntityType == "RedeemedCount")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            RedeemedCount RedeemedCount = new RedeemedCount();
                            RedeemedCount = uow.RedeemedCountRepo.GetById(log.EntityId);
                            if (RedeemedCount != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = "";// "Redeemed Count";// uow.RedeemedCountRepo.GetById(Convert.ToInt32(log.UserId)).Title;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;
                            }
                        }

                        if (log.EntityType == "Setting")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            Setting Setting = new Setting();
                            Setting = uow.SettingRepo.GetById(log.EntityId);
                            if (Setting != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = "";// "Setting";//uow.SettingRepo.GetById(Convert.ToInt32(log.UserId)).Title;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;
                            }
                        }

                        if (log.EntityType == "Template")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            Template Template = new Template();
                            Template = uow.TemplateRepo.GetById(log.EntityId);
                            if (Template != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = Template.Title;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;
                            }
                        }

                        if (log.EntityType == "User")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            User User = new User();
                            User = uow.UserRepo.GetById(log.EntityId);
                            if (User != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = User.Name;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;
                            }
                        }

                        if (log.EntityType == "Location")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        {
                            Location Location = new Location();
                            Location = uow.LocationRepo.GetById(log.EntityId);
                            if (Location != null)
                            {
                                ActivityLogDTO ActivityLogDTO = new ActivityLogDTO();
                                if (log.UserId != null)
                                {
                                    ActivityLogDTO.User = uow.UserRepo.GetById(Convert.ToInt32(log.UserId)).Name;
                                }

                                if (log.PartnerId != null)
                                {
                                    ActivityLogDTO.Partner = uow.PartnerRepo.GetById(Convert.ToInt32(log.PartnerId)).Name;
                                }

                                if (log.ClientId != null)
                                {
                                    ActivityLogDTO.Client = uow.ClientRepo.GetById(Convert.ToInt32(log.ClientId)).Company;
                                }

                                ActivityLogDTO.EntityName = Location.Name;
                                ActivityLogDTO.Date = log.Date;
                                ActivityLogDTO.EntityType = log.EntityType;
                                ActivityLogDTO.OperationType = log.OperationType;
                                ActivityLogDTO.Id = log.Id;
                                ActivityLogDTOList.Add(ActivityLogDTO);
                                j = 1;
                            }
                        }

                        i = i + j;
                        if (i >= Top)
                        {
                            return ActivityLogDTOList;
                        }

                    }

                }
                return ActivityLogDTOList;

            }
            catch (Exception)
            {
                //return ActivityLogDTOList;
                throw;
            }
        }
        //Get group list as per contact id
        public static List<GroupDTO> GetContactIdWiseGroups(int ContactId)
        {
            List<GroupContactDTO> GroupContactDTOList = new List<GroupContactDTO>();
            List<GroupDTO> GroupDTOList = new List<GroupDTO>();
            List<Group> GroupList = new List<Group>();

            try
            {

                UnitOfWork uow = new UnitOfWork();
                IEnumerable<GroupContact> GroupContact = uow.GroupContactRepo.GetAll().Where(e => e.ContactId == ContactId).AsQueryable();

                if (GroupContact != null)
                {
                    foreach (var item in GroupContact)
                    {
                        Group Group = new Group();
                        Group = uow.GroupRepo.GetById(item.GroupId);
                        GroupList.Add(Group);
                    }

                    if (GroupList != null)
                    {
                        foreach (var item in GroupList)
                        {
                            GroupDTOList.Add(Transform.GroupToDTO(item));
                        }
                    }

                    return GroupDTOList;// ContactDTOList.Skip(skip).Take(take).ToList();
                }
                return GroupDTOList;
            }
            catch (Exception)
            {
                throw;
            }
        }
 public static GroupDTO GroupToDTO(Group Group)
 {
     if (Group == null) return null;
      Mapper.CreateMap<Group, GroupDTO>();
      Mapper.CreateMap<Contact, ContactDTO>();
      GroupDTO GroupDTO = Mapper.Map<GroupDTO>(Group);
      //ContactDTO ContactDTO = Mapper.Map<ContactDTO>(Group.Contacts);
      //var GroupDTO = AutoMapper.Mapper.Map<GroupDTO>(Group);
      return GroupDTO;
 }