public async Task <bool> Update(UpdateAdvertiseDTO advertise, string filePath) { var dbAd = await this.advertiseRepository.All().FirstOrDefaultAsync(a => a.Id == advertise.Id); dbAd.Category = advertise.Category; dbAd.ContactPerson = advertise.ContactPerson; dbAd.ContactEmail = advertise.ContactEmail; dbAd.ContactPhone = advertise.ContactPhone; dbAd.Title = advertise.Title; dbAd.Type = advertise.Type; dbAd.CreatedOn = DateTime.UtcNow; dbAd.Property = new Data.Models.Property { CreatedOn = DateTime.UtcNow, Country = advertise.Property.Country, Town = advertise.Property.Town, Location = advertise.Property.Location, Description = advertise.Property.Description, Lease = advertise.Property.Lease, Price = advertise.Property.Price, Deposit = advertise.Property.Deposit, Images = (await this.filesService.SaveFiles(advertise.Property.Images, filePath).ToListAsync()) .Select(img => new Image { Name = img, CreatedOn = DateTime.UtcNow }) .ToHashSet() }; await this.advertiseRepository.AddAsync(dbAd); return((await this.advertiseRepository.SaveChangesAsync()) != 0); }
public async Task <ActionResult> Update(UpdateAdvertiseDTO advertise) { var root = Path.Combine(this.env.ContentRootPath, "Images"); var isUpdated = await this.advertisesService.Update(advertise, root); return(this.Ok(isUpdated)); }