public async Task <ApiResponse> addOrUpdateColor(ColorDto dto)
        {
            try
            {
                // Kiem tra ten
                if (dto.name == null)
                {
                    return(new ApiResponse("Tên không được để trống", dto.name, 400));
                }
                // add color
                // Id == Guid empty
                if (dto.Id == Guid.Empty)
                {
                    var color = _mapper.Map <Color>(dto);
                    await _colorService.AddAsync(color);

                    return(new ApiResponse("Thêm mới thành công", dto.name, 200));
                }

                // find id
                var getColor = await _colorService.GetByIdAsync(dto.Id);

                if (getColor == null)
                {
                    return(new ApiResponse($"Không tìm thấy Color: {getColor}", getColor, 404));
                }
                var updateColor = _mapper.Map(dto, getColor);
                await _colorService.UpdateAsync(updateColor);

                return(new ApiResponse($"Sửa thành công by Id: {dto.Id}", updateColor, 201));
            }catch (Exception ex)
            {
                return(new ApiResponse($"Error {ex}", ex, 400));
            }
        }
コード例 #2
0
        public async Task <IActionResult> AddAsync(ColorDto colorDto)
        {
            var color = _mapper.Map <ColorDto, Color>(colorDto);
            await _colorService.AddAsync(ContentRootPath, color);

            return(Ok(color));
        }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] CreateColor command)
        {
            command.Id = Guid.NewGuid();
            await _colorService.AddAsync(_mapper.Map <ColorDTO>(command));

            return(Created($"/events/{command.Id}", null));
        }
コード例 #4
0
        public async Task <IActionResult> Add(ColorAddDto addDto)
        {
            var result = await _colorService.AddAsync(_mapper.Map <Color>(addDto));

            if (result.Success)
            {
                return(Created("", result));
            }
            return(BadRequest(result));
        }
コード例 #5
0
        public async Task <IActionResult> AddAsync(ColorAddDto colorAddDto)
        {
            var result = await _colorService.AddAsync(colorAddDto);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
コード例 #6
0
        public async Task <IActionResult> Colors(ViewModel.InformationViewModel vmodel)
        {
            isAjax = HttpContext.Request.IsAjax("POST");
            if (isAjax)
            {
                if (ModelState.IsValid)
                {
                    await FColorServices.AddAsync(vmodel.Colors);

                    return(new JsonResult("عملیات با موفقیت ذخیره شد"));
                }
            }
            return(new JsonResult("خطا در ثبت عملیات"));
        }
コード例 #7
0
        public async Task <IActionResult> CreateColor(CreateColorViewModel createColorViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(createColorViewModel));
            }

            var colorDto = _mapper.Map <ColorDTO>(createColorViewModel);
            await _colorService.AddAsync(colorDto);

            await _colorService.SaveChangesAsync();

            return(RedirectToAction(nameof(GetColorList), CURRENT_CONTROLLER_NAME));
        }