public async Task <ActionResult <ExcerciseOutputModel> > Edit(ExcerciseEditModel model) { var result = await excerciseService.Edit(model); if (!result.Succeeded) { return(BadRequest(result.Errors)); } return(result.Data); }
public async Task <Result <ExcerciseOutputModel> > Edit(ExcerciseEditModel model) { var excercise = await db.Excercises .FirstOrDefaultAsync(x => x.Id == model.Id && x.IsDeleted == false); if (excercise == null) { return(null); } if (excercise.ExcerciseType != model.ExcerciseType) { excercise.ExcerciseType = model.ExcerciseType; } if (excercise.ExcerciseDifficulty != model.ExcerciseDifficulty) { excercise.ExcerciseDifficulty = model.ExcerciseDifficulty; } if (excercise.Name != model.Name) { excercise.Name = model.Name; } if (excercise.ShortDescription != model.ShortDescription) { excercise.ShortDescription = model.ShortDescription; } if (excercise.Url != model.Url) { excercise.Url = model.Url; } await db.SaveChangesAsync(); return(mapper.Map <ExcerciseOutputModel>(excercise)); }