Ejemplo n.º 1
0
        public async Task <ResponseModel> UpdateLevelStudyGuideAsync(Guid id, LevelStudyGuideManageModel levelStudyGuideManageModel)
        {
            var levelStudyGuide = await _repository.GetByIdAsync(id);

            if (levelStudyGuide == null)
            {
                return(new ResponseModel()
                {
                    StatusCode = System.Net.HttpStatusCode.NotFound,
                    Message = "This levelStudyGuide is not exist"
                });
            }
            else
            {
                var existedLevelStudyGuideName = await _repository.FetchFirstAsync(x => x.Name == levelStudyGuideManageModel.Name && x.Id != id);

                if (existedLevelStudyGuideName != null)
                {
                    return(new ResponseModel()
                    {
                        StatusCode = System.Net.HttpStatusCode.BadRequest,
                        Message = "LevelStudyGuide " + levelStudyGuideManageModel.Name + " is exist on system. Please try again!",
                    });
                }
                else
                {
                    levelStudyGuideManageModel.GetLevelStudyGuideFromModel(levelStudyGuide);
                    return(await _repository.UpdateAsync(levelStudyGuide));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <ResponseModel> CreateLevelStudyGuideAsync(LevelStudyGuideManageModel levelStudyGuideManageModel)
        {
            var levelStudyGuide = await _repository.FetchFirstAsync(x => x.Name == levelStudyGuideManageModel.Name);

            if (levelStudyGuide != null)
            {
                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.BadRequest,
                    Message = "This LevelStudyGuide is exist"
                });
            }
            else
            {
                levelStudyGuide = new LevelStudyGuide();
                levelStudyGuideManageModel.GetLevelStudyGuideFromModel(levelStudyGuide);
                await _repository.InsertAsync(levelStudyGuide);

                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.OK,
                    Data = new LevelStudyGuideViewModel(levelStudyGuide),
                });
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Update(Guid id, [FromBody] LevelStudyGuideManageModel levelStudyGuideManageModel)
        {
            var response = await _levelStudyGuideService.UpdateLevelStudyGuideAsync(id, levelStudyGuideManageModel);

            return(new CustomActionResult(response));
        }