//public IResponseDTO GetAllAdvertisement()
        //{
        //    try
        //    {
        //        var Advertisements = _AdvertisementRepositroy.GetAll().OrderByDescending(x => x.CreationDate);

        //        foreach (var ads in Advertisements)
        //        {
        //            if (ads.CategoryId != null)
        //            {
        //                _AdvertisementCategoryRepositroy.Add(new AdvertisementCategory()
        //                {
        //                    AdsCategoryId = Guid.NewGuid(),
        //                    CategoryId = ads.CategoryId,
        //                    AdsId = ads.AdsId,
        //                    Available = true,
        //                    CreationDate = (DateTime)ads.CreationDate
        //                });
        //            }
        //            if (ads.CityId != null)
        //            {
        //                _AdvertisementCityRepositroy.Add(new AdvertisementCity()
        //                {
        //                    AdsCityId = Guid.NewGuid(),
        //                    CityId = ads.CityId,
        //                    AdsId = ads.AdsId,
        //                    Available = true,
        //                    CreationDate = (DateTime)ads.CreationDate
        //                });
        //            }
        //            if (!string.IsNullOrEmpty(ads.AdsImage))
        //            {
        //                _AdvertisementAttachRepositroy.Add(new AdvertisementAttach()
        //                {
        //                    AdsAttachId = Guid.NewGuid(),
        //                    AdsId = ads.AdsId,
        //                    Available = true,
        //                    CreationDate = (DateTime)ads.CreationDate,
        //                    AttachType = 0,
        //                    AttachUrl = ads.AdsImage,
        //                });
        //            }
        //            if (!string.IsNullOrEmpty(ads.AdsVideo))
        //            {
        //                _AdvertisementAttachRepositroy.Add(new AdvertisementAttach()
        //                {
        //                    AdsAttachId = Guid.NewGuid(),
        //                    AdsId = ads.AdsId,
        //                    Available = true,
        //                    CreationDate = (DateTime)ads.CreationDate,
        //                    AttachType = 1,
        //                    AttachUrl = ads.AdsVideo,
        //                });
        //            }
        //        }
        //        _unitOfWork.Commit();
        //        var AdvertisementsList = _mapper.Map<List<AdvertisementVM>>(Advertisements);
        //        _response.Data = AdvertisementsList;
        //        _response.IsPassed = true;
        //        _response.Message = "Done";
        //    }
        //    catch (Exception ex)
        //    {
        //        _response.Data = null;
        //        _response.IsPassed = false;
        //        _response.Message = "Error " + ex.Message;
        //    }
        //    return _response;

        //}


        public IResponseDTO GetNewAdvertisement(int page, Guid CustomerId)
        {
            try
            {
                var paging = new DTO.Pageing();
                paging.pageNumber = page;
                var Advertisements = _AdvertisementRepositroy.Get(x => x.Available == true, includeProperties: "Market")
                                     .OrderBy(x => x.StartDate)
                                     .Skip(paging.skip).Take(paging.pageSize);
                foreach (var add in Advertisements)
                {
                    _AdvertisementViewRepositroy.Add(new AdvertisementView()
                    {
                        AdsViewId  = Guid.NewGuid(),
                        AdsId      = add.AdsId,
                        CustomerId = CustomerId,
                    });
                }
                _unitOfWork.Commit();
                var AdvertisementsList = _mapper.Map <List <AdvertisementVM2> >(Advertisements);
                _response.Data     = AdvertisementsList;
                _response.IsPassed = true;
                _response.Message  = "Done";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + ex.Message;
            }
            return(_response);
        }
 public IResponseDTO GetAdvertisementByCategory(int page, Guid categoryId, Guid cityId, Guid CustomerId)
 {
     try
     {
         var paging = new DTO.Pageing();
         paging.pageNumber = page;
         var Advertisements = _AdvertisementRepositroy.Get(x => x.Available == true,
                                                           includeProperties: "Market,AdvertisementCity,AdvertisementCategory")
                              .Skip(paging.skip).Take(paging.pageSize);
         var AdvertisementsList = new List <AdvertisementVM2>();
         foreach (var add in Advertisements)
         {
             var Category = add.AdvertisementCategory.FirstOrDefault(x => x.CategoryId == categoryId);
             if (Category == null)
             {
                 continue;
             }
             var City = add.AdvertisementCity.FirstOrDefault(x => x.CityId == cityId);
             if (City == null)
             {
                 continue;
             }
             _AdvertisementViewRepositroy.Add(new AdvertisementView()
             {
                 AdsViewId  = Guid.NewGuid(),
                 AdsId      = add.AdsId,
                 CustomerId = CustomerId,
             });
             AdvertisementsList.Add(_mapper.Map <AdvertisementVM2>(add));
         }
         _unitOfWork.Commit();
         //var AdvertisementsList = _mapper.Map<List<AdvertisementVM2>>(Advertisements);
         _response.Data     = AdvertisementsList;
         _response.IsPassed = true;
         _response.Message  = "Done";
     }
     catch (Exception ex)
     {
         _response.Data     = null;
         _response.IsPassed = false;
         _response.Message  = "Error " + ex.Message;
     }
     return(_response);
 }