示例#1
0
        public ColorCreateResponse Create([FromBody] ColorCreateRequest request)
        {
            ColorCreateResponse response = new ColorCreateResponse();

            colorRepository.Create(colorConvertor.toEntity(request));

            metaColorProvider.Reload();

            response.Status = 1;
            return(response);
        }
示例#2
0
        public async Task <string> Create(ColorCreateRequest request)
        {
            var color = new productColor()
            {
                idColor   = request.IdColor,
                colorName = request.Name,
            };

            _context.productColor.Add(color);
            await _context.SaveChangesAsync();

            return(color.idColor);
        }
示例#3
0
        public async Task <IActionResult> Create([FromForm] ColorCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var idColor = await _colorService.Create(request);


            var product = await _colorService.GetById(idColor);

            return(CreatedAtAction(nameof(GetById), new { id = idColor }, product));
        }
        public ColorEntity toEntity(ColorCreateRequest request)
        {
            ColorEntity entity = new ColorEntity();

            var item = request.Item;

            entity.ColorId        = item.ColorId;
            entity.ColorName      = item.ColorName;
            entity.DataStatus     = 1;
            entity.CreateTime     = TimeConvertor.FromMilliTicks(TimeConvertor.ToMilliTicks(DateTime.Now));
            entity.LastUpdateTime = TimeConvertor.FromMilliTicks(TimeConvertor.ToMilliTicks(DateTime.Now));

            return(entity);
        }
示例#5
0
        public async Task <IActionResult> Create([FromForm] ColorCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View(request));
            }

            var result = await _colorApiClient.CreateColor(request);

            if (result)
            {
                TempData["result"] = "Thêm mới Color thành công";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Thêm Color thất bại");
            return(View(request));
        }
示例#6
0
        public async Task <bool> CreateColor(ColorCreateRequest request)
        {
            var sessions = _httpContextAccessor
                           .HttpContext
                           .Session
                           .GetString(SystemConstants.AppSettings.Token);

            var languageId = _httpContextAccessor.HttpContext.Session.GetString(SystemConstants.AppSettings.DefaultLanguageId);

            var client = _httpClientFactory.CreateClient();

            client.BaseAddress = new Uri(_configuration[SystemConstants.AppSettings.BaseAddress]);
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions);

            var requestContent = new MultipartFormDataContent();

            requestContent.Add(new StringContent(request.IdColor.ToString()), "IdColor");
            requestContent.Add(new StringContent(request.Name.ToString()), "Name");

            var response = await client.PostAsync($"/api/colors/", requestContent);

            return(response.IsSuccessStatusCode);
        }