public async Task <bool> Edit(AdEditIm input) { var ad = await this.db.Ads.FindAsync(input.Id); if (ad == null) { throw new NotFoundException($"{ad} doesn't exists"); } if (ad.UserId != this.user.Id) { throw new InvalidOperationException("You are not the owner of this ad"); } var category = await this.db.Categories.FirstOrDefaultAsync(c => c.Id == input.CategoryId); if (category == null) { throw new InvalidOperationException($"This {input.CategoryId} doesn't exits"); } this.mapper.Map(input, ad); this.db.Entry(ad).State = EntityState.Modified; await this.db.SaveChangesAsync(); return(true); }
public async Task <ActionResult <bool> > Edit(AdEditIm input) => await this.ads.Edit(input);