public async Task <IActionResult> Save(AdvertisementDto model) { model.CategoryIds = model.CategoryIds?.Replace("null", ""); var b = await AdsService.AddOrUpdateSavedAsync(a => a.Id, model.Mapper <Advertisement>()) > 0; return(ResultData(null, b, b ? "保存成功" : "保存失败")); }
public async Task <IActionResult> Save([FromBodyOrDefault] AdvertisementDto model) { var entity = AdsService[model.Id] ?? new Advertisement(); model.CategoryIds = model.CategoryIds?.Replace("null", ""); model.Regions = Regex.Replace(model.Regions ?? "", @"(\p{P}|\p{Z}|\p{S})+", "|"); if (model.RegionMode == RegionLimitMode.All) { model.Regions = null; } if (model.Types.Contains(AdvertiseType.Banner.ToString("D")) && string.IsNullOrEmpty(model.ImageUrl)) { return(ResultData(null, false, "宣传大图不能为空")); } if (model.Types.Length > 3 && string.IsNullOrEmpty(model.ThumbImgUrl)) { return(ResultData(null, false, "宣传小图不能为空")); } Mapper.Map(model, entity); var b = await AdsService.AddOrUpdateSavedAsync(a => a.Id, entity) > 0; return(ResultData(null, b, b ? "保存成功" : "保存失败")); }
public async Task <AdvertisementResponseDto> SaveAdvertisement(AdvertisementDto advertisementDto) { if (advertisementDto is null) { throw new ArgumentNullException(nameof(AdvertisementDto)); } try { UnitOfWork.StartTransaction(); var advertisement = new Advertisement(advertisementDto.UniversityId, advertisementDto.CompanyId, advertisementDto.Max, advertisementDto.Unlimited); await UnitOfWork.AdvertisementRepository.InsertOne(advertisement); await UnitOfWork.CommitTransaction(); return(Mapper.Map <Advertisement, AdvertisementResponseDto>(advertisement)); } catch (Exception ex) { await UnitOfWork.RollBackTransaction(); throw new InvalidOperationException(ex.Message); } }
public async Task OnGetAsync(long?id) { if (id.HasValue) { Dto = await _service.GetByIdAsync(id.Value); if (Dto == null) { throw new KuDataNotFoundException(); } BindBoards = (await _service.GetAdvertisementBoardsAsync(Dto.Id)).Select(x => x.Id).ToArray(); ViewData["Mode"] = "Edit"; } else { Dto = new AdvertisementDto(); ViewData["Mode"] = "Add"; } //广告位列表取得 Boards = await _boardService.GetListAsync(new AdvertisementBoardSearch { IsDeleted = false }, null); if (BindBoards == null) { BindBoards = new long[] { }; } }
public async Task<IActionResult> Save(AdvertisementDto model) { model.CategoryId = model.CategoryId?.Replace("null", ""); var entity = AdsService.GetById(model.Id); if (entity != null) { Mapper.Map(model, entity); bool b1 = await AdsService.SaveChangesAsync() > 0; return ResultData(null, b1, b1 ? "修改成功" : "修改失败"); } bool b = AdsService.AddEntitySaved(model.Mapper<Advertisement>()) != null; return ResultData(null, b, b ? "添加成功" : "添加失败"); }
public async Task <IActionResult> CreateAdvertisement(int id) { if (id <= 0) { throw new ArgumentException("Id is not valid!"); } var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var dto = new AdvertisementDto { CarId = id, UserId = userId }; await this.advertisementService.AddAdvertisement(dto); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> AddAdvertisement(AdvertisementDto advertisement) { IActionResult result = Ok(); try { Advertisement advertisementToAdd = _advertisementAssembler.Assemble(advertisement); await _advertisementDao.SaveAdvertisementAsync(advertisementToAdd); } catch (Exception e) { result = Problem(e.Message); } return(result); }
public async Task <IActionResult> Save(AdvertisementDto model) { model.CategoryIds = model.CategoryIds?.Replace("null", ""); if (model.Types.Contains(AdvertiseType.Banner.ToString("D")) && string.IsNullOrEmpty(model.ImageUrl)) { return(ResultData(null, false, "宣传大图不能为空")); } if (model.Types.Length > 3 && string.IsNullOrEmpty(model.ThumbImgUrl)) { return(ResultData(null, false, "宣传小图不能为空")); } var b = await AdsService.AddOrUpdateSavedAsync(a => a.Id, model.Mapper <Advertisement>()) > 0; return(ResultData(null, b, b ? "保存成功" : "保存失败")); }
public Advertisement Assemble(AdvertisementDto dto) { Assert.IsNotBlank(dto.AdType.ToString()); Assert.IsNotBlank(dto.Category); Assert.IsNotBlank(dto.Content); Assert.IsNotBlank(dto.Cost); Advertisement result = new Advertisement(); Enum.TryParse(dto.AdType.ToString(), out AdType adType); result.AdType = adType; result.Category = new Category(dto.Category); result.Cost = decimal.Parse(dto.Cost); result.Content = dto.Content; result.Tags = _tagAssembler.Assemble(dto.Tags); return(result); }
public async Task <AdvertisementDto> AddAdvertisement(AdvertisementDto dto) { var newAd = this.mapper.Map <Advertisement>(dto); var adExists = await this.context.Advertisements.ContainsAsync(newAd); if (adExists) { throw new ArgumentException($"There is already such ad in the db!"); } var adId = await GetNextValue(); newAd.Id = adId; newAd.UserId = dto.UserId; newAd.PublishDate = DateTime.Now; await this.context.Advertisements.AddAsync(newAd); await this.context.SaveChangesAsync(); return(this.mapper.Map <AdvertisementDto>(newAd)); }
public async Task <ActionResult <AdvertisementResponseDto> > Patch([FromBody] AdvertisementDto model, string id) { try { if (!ModelState.IsValid) { return(BadRequest()); } var advertisementResponseDto = await _AdvertisementService.UpdateAdvertisement(id, model); if (advertisementResponseDto is null) { return(BadRequest()); } return(advertisementResponseDto); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public Task <AdvertisementResponseDto> UpdateAdvertisement(string advertisementId, AdvertisementDto advertisementDto) { throw new NotImplementedException(); }