Esempio n. 1
0
        public async Task <IActionResult> CreateMultiple(ICollection <KhoaForCreateMultipleDto> danhSachKhoa)
        {
            try
            {
                var validationResult = _repo.ValidateBeforeCreateMultiple(danhSachKhoa);

                if (validationResult.IsValid)
                {
                    var result = await _repo.CreateMultiple(danhSachKhoa);

                    return(StatusCode(201, new SuccessResponseDto
                    {
                        Message = "Nhập dữ liệu cho " + _entityName + " thành công!",
                        Result = new SuccessResponseResultWithSingleDataDto
                        {
                            Data = result
                        }
                    }));
                }
                else
                {
                    return(StatusCode(500, new FailedResponseDto
                    {
                        Message = "Nhập dữ liệu cho " + _entityName + " thất bại!",
                        Result = new FailedResponseResultDto
                        {
                            Errors = validationResult.Errors
                        }
                    }));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500, new FailedResponseDto
                {
                    Message = "Nhập dữ liệu cho " + _entityName + " thất bại!",
                    Result = new FailedResponseResultDto
                    {
                        Errors = e
                    }
                }));
            }
        }