Example #1
0
        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));
                }
            }
        }
Example #2
0
        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),
                });
            }
        }
Example #3
0
        public async Task <IActionResult> Update(Guid id, [FromBody] LevelManageModel levelManageModel)
        {
            var response = await _levelService.UpdateLevelAsync(id, levelManageModel);

            return(new CustomActionResult(response));
        }
Example #4
0
        public async Task <IActionResult> Create([FromBody] LevelManageModel levelManageModel)
        {
            var response = await _levelService.CreateLevelAsync(levelManageModel);

            return(new CustomActionResult(response));
        }