Exemplo n.º 1
0
        public bool DeleteAdvertise(int ID)
        {
            if (ID <= 0)
            {
                throw new HttpResponseException()
                      {
                          Status = (int)ApiResultModel.CodeEnum.IllegalRequest
                      };
            }

            string physicalPath = $"{_hostingEnvironment.ContentRootPath}{_config.GetValue<string>("ImagesUploadPath")}";

            AdvertiseCondition condition = new AdvertiseCondition();

            condition.ID = ID;

            Advertise advertise = _advertiseService.SearchAdvertises(condition).FirstOrDefault();

            if (advertise == null)
            {
                throw new HttpResponseException()
                      {
                          Status = (int)ApiResultModel.CodeEnum.ObjectNotFound
                      };
            }

            CommonUtilities.DeleteImageFromUrl(advertise.ResourceUrl, physicalPath, _config.GetValue <string>("ImagesUploadPath"));

            return(_advertiseService.DeleteAdvertise(ID));
        }
Exemplo n.º 2
0
        public ResultObject GetAdvertises(AdvertiseCondition condition)
        {
            List <Advertise> advertise = _advertiseService.SearchAdvertises(condition);

            ResultObject result = new ResultObject()
            {
                Total = advertise.Count,
                Data  = advertise
            };

            return(result);
        }
Exemplo n.º 3
0
        public List <Advertise> SearchAdvertises(AdvertiseCondition condition)
        {
            var advertise = _advertiseRepository.GetAll();

            if (condition.ID > 0)
            {
                advertise = advertise.Where(model => model.ID.Equals(condition.ID));
            }

            if (!string.IsNullOrEmpty(condition.ResourceUrl))
            {
                advertise = advertise.Where(model => model.ResourceUrl.Equals(condition.ResourceUrl));
            }

            if (condition.ShowInTimeData)
            {
                DateTime nowTime = DateTime.Now;
                advertise = advertise.Where(model => model.StartDate >= nowTime && model.EndDate <= nowTime);
            }

            return(advertise.ToList());
        }