//Get Partner's Latest Activities
        public static List<ActivityLogDTO> GetPartnerLatestActivities(int PartnerId, 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.PartnerId == Convert.ToInt32(PartnerId)).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 == "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 == "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 == "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 == "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 == "SMSGateway")// && log.OperationType == "Added" || log.OperationType == "Modified")
                        //{
                        //    SMSGateway SMSGateway = new SMSGateway();
                        //    SMSGateway = uow.SMSGatewayRepo.GetById(log.EntityId);
                        //    if (SMSGateway != 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 = SMSGateway.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;
            }
        }
        //Create credit request
        public static CreditRequestDTO Create(CreditRequestDTO CreditRequestDTO)
        {
            try
            {
                CreditRequestDTO CreditRequestDTONew = new CreditRequestDTO();

                PartnerDTO PartnerDTO = new PartnerDTO();
                ClientDTO ClientDTO = new ClientDTO();
                UserDTO UserDTO = new UserDTO();

                PartnerDTO = PartnerService.GetById(CreditRequestDTO.PartnerId);
                ClientDTO = ClientService.GetById(CreditRequestDTO.ClientId);
                UserDTO = UserService.GetById(CreditRequestDTO.RequestedBy);

                GlobalSettings.LoggedInClientId = ClientDTO.Id;
                GlobalSettings.LoggedInUserId = UserDTO.Id;
                int PartnerId = PartnerDTO.Id;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                if (CreditRequestDTO.RequestedCredit <= 0)
                {
                    return null; //0
                }
                var CreditRequest = new CreditRequest();
                using (var uow = new UnitOfWork())
                {
                    CreditRequest = Transform.CreditRequestToDomain(CreditRequestDTO);
                    CreditRequest.Date = System.DateTime.Now;
                    CreditRequest.OldBalance = ClientDTO.SMSCredit;
                    CreditRequest.IsProvided = false;
                    //CreditRequest.ProvidedCredit = CreditRequest.RequestedCredit;
                    CreditRequest.Amount = CreditRequest.RequestedCredit * CreditRequest.RatePerSMS;
                    double tax = (CreditRequest.Amount * Convert.ToDouble(CreditRequest.Tax)) / 100;
                    CreditRequest.TaxAmount = tax;
                    CreditRequest.GrandTotal = CreditRequest.Amount + tax;

                    bool IsOnlinepaymentSuccess = Onlinepayment(CreditRequest.GrandTotal);

                    if (IsOnlinepaymentSuccess == true)
                    {
                        //CreditRequest.IsPaymentSuccessful = true;
                        //CreditRequest.PaymentDate = System.DateTime.Now;
                        CreditRequest.ProvidedDate = System.DateTime.Now;
                        CreditRequest.IsProvided = true;
                        CreditRequest.IsBillGenerated = true;
                        CreditRequest.PaymentMode = PaymentMode.Card;
                        CreditRequest.PaymentDate = System.DateTime.Now;
                        CreditRequest.IsPaid = true;
                        CreditRequest.ProvidedCredit = CreditRequest.RequestedCredit;

                        uow.CreditRequestRepo.Insert(CreditRequest);
                        uow.SaveChanges();

                        ClientDTO.SMSCredit = ClientDTO.SMSCredit + CreditRequest.RequestedCredit;
                        ClientService.Edit(ClientDTO);

                    }
                    else
                    {
                        //CreditRequest.IsPaymentSuccessful = false;
                        CreditRequest.IsPaid = false;
                        uow.CreditRequestRepo.Insert(CreditRequest);
                        uow.SaveChanges();
                    }

                    //Update TotalAppliedCredit
                    ClientDTO.TotalAppliedCredit = ClientDTO.TotalAppliedCredit + CreditRequest.RequestedCredit;
                    ClientService.Edit(ClientDTO);

                    //Generate Link to provide mail trhough mail
                    string APILink = ConfigurationManager.AppSettings["APILink"].ToString() + "api/CreditRequest/ProvideCreditByMailLink?CreditRequestId=" + CreditRequest.Id;

                    // Send Email To Partner
                    bool IsMailSent = CommonService.SendEmail("SMS Credit Request", "Hello " + PartnerDTO.Name + ", <br/><br/> The New request of " + CreditRequest.RequestedCredit + " credits applied by " + ClientDTO.Company + "<br/><br/> <a href=" + APILink + ">Approve</a>", PartnerDTO.Email, "", false);

                    CreditRequestDTONew = GetById(CreditRequest.Id);
                    if (CreditRequest.PaymentMode == PaymentMode.Card)
                    {
                        CreditRequestDTONew.OnlinePaymentURL = OnlinePaymentLinkWithTemperproofData(UserDTO.Email, CreditRequest.GrandTotal, UserDTO.Mobile, UserDTO.Name, CreditRequest.Id);
                    }
                    return (CreditRequestDTONew); //.Id);

                }

            }
            //catch (LoggedInUserException)
            //{
            //    throw new System.TimeoutException();
            //}
            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;
            }
        }
 public static CreditRequestDTO CreditRequestToDTO(CreditRequest CreditRequest)
 {
     if (CreditRequest == null) return null;
     Mapper.CreateMap<CreditRequest, CreditRequestDTO>();
     CreditRequestDTO CreditRequestDTO = Mapper.Map<CreditRequestDTO>(CreditRequest);
     return CreditRequestDTO;
 }