Пример #1
0
        public async System.Threading.Tasks.Task <ActionResult> DetailAsync(int id = 0)
        {
            var advertisement = await _advertisementService.GetAdvertisementById(id);

            if (advertisement != null)
            {
                AdvertisementViewModel viewModel = _mapper.Map <Advertisement, AdvertisementViewModel>(advertisement);
                viewModel.PositionAdvertisement = ((Common.AdvertisementPosition)Enum.ToObject(typeof(Common.AdvertisementPosition), advertisement.Position)).ToString();
                return(View(viewModel));
            }
            ModelState.AddModelError(string.Empty, Constants.UnknowErrorMessage);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            var advertisement = _advertisementService.GetAdvertisementById(id);

            if (advertisement == null || advertisement.Deleted)
            {
                //No advertisement found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new ModelsMapper().CreateMap <Advertisement, AdvertisementModel>(advertisement);

            PrepareAdvertisementModel(model, null, false, true);
            //AddLocales(_languageService, model.Locales);
            //PrepareAclModel(model, null, false);
            PrepareStoresMappingModel(model, null, false);

            return(View(model));
        }
        public HttpResponseMessage Detailed(int id)
        {
            var advertisement = _advertisementService.GetAdvertisementById(id);

            if (advertisement == null)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "该数据不存在")));
            }
            else
            {
                var advertisementDetail = new AdvertisementModel
                {
                    Id           = advertisement.Id,
                    Title        = advertisement.Title,
                    Detail       = advertisement.Detail,
                    Continue     = advertisement.Continue.ToString(CultureInfo.InvariantCulture),
                    ContentId    = advertisement.Content.Id,
                    ContentTitle = advertisement.Content.Title
                };
                return(PageHelper.toJson(advertisementDetail));
            }
        }
        public async Task <ActionResult <AdvertisementDTO> > CreateUser([FromBody] AdvertisementDTO createAdvertisementResource)
        {
            // var validator = new CreateUserResourceValidator();
            // var validationResult = await validator.ValidateAsync(createUserResource);

            // if (!validationResult.IsValid)
            //     return BadRequest(validationResult.Errors); // this needs refining, but for demo it is ok

            var advertisementToCreate = _mapper.Map <AdvertisementDTO, Advertisement>(createAdvertisementResource);

            var newAdvertisement = await _advertisementService.CreateAdvertisement(advertisementToCreate);

            var advertisement = await _advertisementService.GetAdvertisementById(newAdvertisement.Id);

            var advertisementResource = _mapper.Map <Advertisement, AdvertisementDTO>(advertisement);

            return(Ok(advertisementResource));
        }
 public HttpResponseMessage GetAdvert(int id)
 {
     try
     {
         var content = _advertisementService.GetAdvertisementById(id).Content;
         var result  = new
         {
             content = content.ConvertImageTakeHost(_webHelper.GetStoreLocation())
         };
         var advertView = new AdvertisementView()
         {
             AdvertisementId = id,
             IPAddress       = _webHelper.GetCurrentIpAddress(),
             ViewOnUtc       = DateTime.UtcNow
         };
         _advertisementService.InsertAdvertisementView(advertView);
         return(ReturnResult(result, 0, ""));
     }
     catch (Exception ex)
     {
         LogException(ex);
         return(ReturnResult("", 1, "读取广告数据出现错误"));
     }
 }