Esempio n. 1
0
        public async Task <ResponseModel> UpdateMajorAsync(Guid id, MajorManageModel majorManageModel)
        {
            var major = await _majorRepository.GetByIdAsync(id);

            if (major == null)
            {
                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.NotFound,
                    Message = "This Major is not exist!"
                });
            }
            else
            {
                var existedMajor = await _majorRepository.FetchFirstAsync(x => x.Name == majorManageModel.Name && x.Id != id);

                if (existedMajor != null)
                {
                    return(new ResponseModel
                    {
                        StatusCode = System.Net.HttpStatusCode.BadRequest,
                        Message = "This Major's name is exist!"
                    });
                }
                else
                {
                    majorManageModel.GetMajorFromModel(major);
                    return(await _majorRepository.UpdateAsync(major));
                }
            }
        }
Esempio n. 2
0
        public async Task <ResponseModel> CreateMajorAsync(MajorManageModel majorManageModel)
        {
            var major = await _majorRepository.FetchFirstAsync(x => x.Name == majorManageModel.Name);

            if (major != null)
            {
                return(new ResponseModel()
                {
                    StatusCode = System.Net.HttpStatusCode.BadRequest,
                    Message = "This Major's name is exist!",
                });
            }
            else
            {
                //var menu = await _menuResponstory.GetByIdAsync(itemManageModel.MenuId);
                major = _mapper.Map <Major>(majorManageModel);
                //item.Menu = menu;

                await _majorRepository.InsertAsync(major);

                major = await GetAll().FirstOrDefaultAsync(x => x.Id == major.Id);

                return(new ResponseModel()
                {
                    StatusCode = System.Net.HttpStatusCode.OK,
                    Data = new MajorViewModel(major)
                });
            }
        }
        public async Task <IActionResult> Update(Guid id, [FromBody] MajorManageModel majorManageModel)
        {
            var response = await _majorService.UpdateMajorAsync(id, majorManageModel);

            return(new CustomActionResult(response));
        }
        public async Task <IActionResult> Create([FromBody] MajorManageModel majorManageModel)
        {
            var response = await _majorService.CreateMajorAsync(majorManageModel);

            return(new CustomActionResult(response));
        }