public async Task <ActionResult> Create(CreateColorVM model) { try { if (!ModelState.IsValid) { return(View(model)); } var color = _mapper.Map <Color>(model); var isExists = await _repo.isExist(color.Title); if (isExists) { ModelState.AddModelError("", "This color already exist"); return(View(model)); } var isSuccess = await _repo.Create(color); if (!isSuccess) { ModelState.AddModelError("", "Something went wrong..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }
public ColorCreateResponse Create([FromBody] ColorCreateRequest request) { ColorCreateResponse response = new ColorCreateResponse(); colorRepository.Create(colorConvertor.toEntity(request)); metaColorProvider.Reload(); response.Status = 1; return(response); }
public ColorDto CreateColor(ColorDto colorDto) { var color = _mapper.Map <Color>(colorDto); int res = _repo.Create(color); if (res == 0) { return(null); } return(colorDto); }
public Color Create(Color color) { if (color.Id != default) { throw new NotSupportedException($"The color id should not be specified"); } else if (string.IsNullOrEmpty(color.Name)) { throw new InvalidDataException("You need to specify the color's name."); } return(_colorRepository.Create(color)); }
public Color Create(Color color) { return(colorRepo.Create(color)); }
public Task CreateColor(Color color) { var entity = _mapper.Map <Entities.Color>(color); return(_colorRepository.Create(entity)); }
public Task CreateColor(Color color) => _colorRepository.Create(color);
public async Task <IActionResult> Create([FromBody] List <CreateImageDto> createImageDto) { foreach (var i in createImageDto) { var mapped = _mapper.Map <Images>(i); await _imageRepository.Create(mapped); await _imageRepository.Save(); var tag = createImageDto.FirstOrDefault(a => a.ImageUrl.ToLower() == i.ImageUrl.ToLower()); if (tag != null) { foreach (var t in tag.Tag) { var findTag = await _tagRepository.Query().FirstOrDefaultAsync(a => a.Name.ToLower() == t.ToString().ToLower()); if (findTag == null) { var newTag = new Tag { Name = t }; await _tagRepository.Create(newTag); await _tagRepository.Save(); await _imagetagRepository.Create(new ImageTag() { TagId = newTag.Id, ImageId = mapped.Id }); await _imagetagRepository.Save(); } else { await _imagetagRepository.Create(new ImageTag() { TagId = findTag.Id, ImageId = mapped.Id }); await _imagetagRepository.Save(); } } } //find tag by name //create file info var fileInfo = _mapper.Map <FileInfo>(i.FileInfo); if (fileInfo != null) { fileInfo.ImageId = mapped.Id; await _fileInfoRepository.Create(fileInfo); await _fileInfoRepository.Save(); } //create color //find if color does not exist foreach (var color in i.Colors) { var mappedColor = _mapper.Map <Color>(color); var findcolor = await _colorRepository.Query().FirstOrDefaultAsync(a => a.Code == mappedColor.Code); var imageColor = new ImageColor() { ImageId = mapped.Id, Level = color.Level }; if (findcolor == null) { //create that color await _colorRepository.Create(mappedColor); await _colorRepository.Save(); imageColor.ColorId = mappedColor.Id; } else { imageColor.ColorId = findcolor.Id; } //add color to ImageColorTable await _imageColorRepository.Create(imageColor); await _imageColorRepository.Save(); } } return(StatusCode(201)); }