public async Task <IActionResult> Update( int id, [FromBody] PromoterUpdateViewModel registration) { //if(id == Guid.Empty) //{ // return NotFound(); //} if (registration == null) { return(BadRequest("Promoter registration not given")); } if (!ModelState.IsValid) { return(BadRequest("The given promoter registration is invalid")); } var result = await _promoterUpdater.Update(id, registration); if (result.Successful()) { return(Ok(result.Body())); } return(BadRequest(result.GetAggregatedErrors())); }
public async Task <IServiceResult <PromoterViewModel> > Update( int id, PromoterUpdateViewModel newData) { var existingPromoter = await _context .Promoters .FirstOrDefaultAsync(p => p.Id == id); if (existingPromoter == null) { return(ServiceResult <PromoterViewModel> .Error( $"Promoter with id {id} does not exist")); } //var instituteResult = await _instituteGetter.Get(newData.InstituteId); //if(!instituteResult.Successful()) //{ // return ServiceResult<PromoterViewModel>.Error(instituteResult.GetAggregatedErrors()); //} //var credentials = new UserCredentials //{ // Email = newData.Email, // Password = newData.Password //}; //var result = await _userUpdater.Update( // existingPromoter.UserId, // credentials, // new RoleType[] { // RoleType.Promoter // }); //if (!result.Successful()) //{ // var errors = result.GetAggregatedErrors(); // return ServiceResult<PromoterViewModel>.Error(errors); //} existingPromoter = _mapper.Map(newData, existingPromoter); _context.Promoters.Update(existingPromoter); await _context.SaveChangesAsync(); var promoterViewModel = _mapper.Map <PromoterViewModel>(existingPromoter); return(ServiceResult <PromoterViewModel> .Success(promoterViewModel)); }