public async Task <IActionResult> Create([FromBody] AdvertCommand command) { try { await _repository.AddAsync(new Advert { Active = command.Active, Date = command.Date, PropertyId = command.PropertyId, CreatorId = (await _userManager.FindByNameAsync(User.Identity.Name)).Id, Items = command.Items?.Select(x => new AdvertItem { Description = x.Value }).ToList() }); await _unitOfWork.Commit(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Update([FromBody] AdvertCommand command) { try { await _repository.UpdateAsync(new Advert { Active = command.Active, Date = command.Date, PropertyId = command.PropertyId, Items = command.Items.Select(x => new AdvertItem { Description = x.Value }).ToList() }); await _unitOfWork.Commit(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }