public async Task <ResponseModel> UpdateLevelAsync(Guid id, LevelManageModel levelManageModel) { var level = await _repository.GetByIdAsync(id); if (level == null) { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.NotFound, Message = "This level is not exist" }); } else { var existedLevelName = await _repository.FetchFirstAsync(x => x.Name == levelManageModel.Name && x.Id != id); if (existedLevelName != null) { return(new ResponseModel() { StatusCode = System.Net.HttpStatusCode.BadRequest, Message = "Level " + levelManageModel.Name + " is exist on system. Please try again!", }); } else { levelManageModel.GetLevelFromModel(level); return(await _repository.UpdateAsync(level)); } } }
public async Task <ResponseModel> CreateLevelAsync(LevelManageModel levelManageModel) { var level = await _repository.FetchFirstAsync(x => x.Name == levelManageModel.Name); if (level != null) { return(new ResponseModel { StatusCode = System.Net.HttpStatusCode.BadRequest, Message = "This Level is exist" }); } else { level = new Level(); levelManageModel.GetLevelFromModel(level); await _repository.InsertAsync(level); return(new ResponseModel { StatusCode = System.Net.HttpStatusCode.OK, Data = new LevelViewModel(level), }); } }