Example #1
0
        //Delete location by id
        public static bool Delete(int Id)
        {
            GlobalSettings.LoggedInClientId = LocationService.GetById(Id).ClientId;
            int PartnerId = ClientService.GetById(Convert.ToInt32(GlobalSettings.LoggedInClientId)).PartnerId;

            GlobalSettings.LoggedInPartnerId = PartnerId;

            bool IsExists = IsChildEntityExist(Id);

            try
            {
                if (IsExists != true)
                {
                    LocationDTO LocationDTO = new LocationDTO();
                    LocationDTO = GetById(Id);
                    UnitOfWork uow = new UnitOfWork();
                    uow.LocationRepo.Delete(Id);
                    uow.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                throw;
            }
        }
        //Get redeemed count list by user id and campaign id
        public static List <RedeemedCountDTO> GetByUserId(int UserId, int CampaignId)
        {
            List <RedeemedCountDTO> RedeemedCountDTOList = new List <RedeemedCountDTO>();

            try
            {
                UnitOfWork uow = new UnitOfWork();
                IEnumerable <RedeemedCount> RedeemedCount = uow.RedeemedCountRepo.GetAll().Where(e => e.UserId == UserId && e.EcouponCampaignId == CampaignId);
                if (RedeemedCount != null)
                {
                    foreach (var item in RedeemedCount)
                    {
                        EcouponCampaignDTO EcouponCampaignDTO = new EcouponCampaignDTO();
                        EcouponCampaignDTO = EcouponCampaignService.GetById(item.EcouponCampaignId);
                        if (EcouponCampaignDTO.ExpiresOn > System.DateTime.Now)
                        {
                            RedeemedCountDTO RedeemedCountDTO = new RedeemedCountDTO();
                            RedeemedCountDTO = Transform.RedeemedCountToDTO(item);

                            UserDTO UserDTO = new UserDTO();
                            UserDTO = UserService.GetById(UserId);
                            RedeemedCountDTO.UserName = UserDTO.Name;
                            RedeemedCountDTO.Location = LocationService.GetById(UserDTO.LocationId).Name;
                            ClientDTO ClientDTO = new ClientDTO();
                            ClientDTO = ClientService.GetById(UserDTO.ClientId);
                            RedeemedCountDTO.ClientName = ClientDTO.Company;

                            RedeemedCountDTOList.Add(RedeemedCountDTO);
                        }
                    }
                }

                return(RedeemedCountDTOList);
            }
            catch
            {
                //  throw;
                return(RedeemedCountDTOList);
            }
        }
        /// <summary>
        /// Get active or inactive Users by Client id
        /// </summary>
        /// <param name="ClientId">Id of the Client</param>
        /// <param name="search">search string</param>
        /// <param name="IsActive">TRUE OR FALSE</param>
        /// <param name="pagingInfo">pagingInfo object</param>
        /// <returns> Returns Active or Inactive user list </returns>
        public static List <UserDTO> GetUsersbyClientIdWithIsActive(int ClientId, string search, bool IsActive, PagingInfo pagingInfo)
        {
            List <UserDTO> UserDTOList = new List <UserDTO>();

            try
            {
                UnitOfWork uow = new UnitOfWork();

                int skip = (pagingInfo.Page - 1) * pagingInfo.ItemsPerPage;
                int take = pagingInfo.ItemsPerPage;

                IQueryable <User> User = uow.UserRepo.GetAll().Where(e => e.ClientId == ClientId && e.IsActive == IsActive).OrderBy(e => e.Name).AsQueryable();// .ToList().Skip(skip).Take(take);
                User = PagingService.Sorting <User>(User, pagingInfo.SortBy, pagingInfo.Reverse);
                User = User.Skip(skip).Take(take);


                if (User != null)
                {
                    foreach (var user in User)
                    {
                        UserDTO UserDTO = new UserDTO();
                        UserDTO = Transform.UserToDTO(user);
                        LocationDTO LocationDTO = new LocationDTO();
                        UserDTO.Location = LocationService.GetById(UserDTO.LocationId).Name;
                        UserDTOList.Add(UserDTO);
                    }

                    if (search != "" && search != null)
                    {
                        //int LocationId = LocationService.GetByLocationName(search, ClientId);
                        string LocationIdString = LocationService.GetLocationIdarrayByName(search, ClientId);

                        bool IsDate = CommonService.IsDate(search);
                        if (IsDate != true)
                        {
                            // string search
                            List <UserDTO>    UserDTOListSearch = new List <UserDTO>();
                            IQueryable <User> UserSearch        = uow.UserRepo.GetAll().Where(e => (e.Email.ToLower().Contains(search.ToLower()) || e.Name.ToLower().Contains(search.ToLower()) || e.FirstName.ToLower().Contains(search.ToLower()) || e.LastName.ToLower().Contains(search.ToLower()) || (e.Mobile != null ? (e.Mobile.Contains(search)) : false) || (LocationIdString != null ? (e.LocationId.ToString().Split(',').Any(LocationId => LocationIdString.Contains(LocationId.ToString()))) : false)) && e.IsActive == IsActive && e.ClientId == ClientId).AsQueryable();//.OrderBy(e => e.Name).ToList().Skip(skip).Take(take); //(e.Location != null ? (e.Location.ToLower().Contains(search.ToLower())) : false)
                            UserSearch = PagingService.Sorting <User>(UserSearch, pagingInfo.SortBy, pagingInfo.Reverse);
                            UserSearch = UserSearch.Skip(skip).Take(take);

                            foreach (var user in UserSearch)
                            {
                                UserDTO UserDTO = new UserDTO();
                                UserDTO = Transform.UserToDTO(user);
                                LocationDTO LocationDTO = new LocationDTO();
                                UserDTO.Location = LocationService.GetById(UserDTO.LocationId).Name;
                                UserDTOListSearch.Add(UserDTO);
                            }
                            return(UserDTOListSearch);
                        }
                        else
                        {
                        }
                    }
                    ////else
                    ////{
                    ////    ////foreach (var item in User)
                    ////    ////{
                    ////    ////    //UserDTO UserDTO = new UserDTO();
                    ////    ////    UserDTOList.Add(Transform.UserToDTO(item));
                    ////    ////}
                    ////}
                }

                return(UserDTOList);
            }
            catch (Exception)
            {
                throw;
            }
        }