public async Task <ApiRequestResult> AddAsync(BrandDto dto) { var command = dto.EntityMap <BrandDto, Brand>(); await _brandRepository.AddAsync(command); return(ApiRequestResult.Success("添加成功")); }
public async Task <CreateBrandResponse> AddAsync(CreateBrandRequest brand) { var brandValidatorResult = new CreateBrandValidator().Validate(brand); var errorResult = new List <BaseResponse <CreateBrandResponse, ErrorsResponse> >(); //errorResult.AddRange(brandValidatorResult.Errors.Select(p => new BaseResponse<CreateBrandResponse, ErrorsResponse>().Error.AddError(p.ErrorMessage))); if (!brandValidatorResult.IsValid) { var response = _mapper.Map <CreateBrandResponse>(errorResult); return(response); } var obj = new Brand() { Id = Guid.NewGuid(), Name = brand.Name, }; await _brandRepository.AddAsync(obj); var result = _mapper.Map <CreateBrandResponse>(obj); return(result); }
protected override async Task Handle(CreateBrandCommand request, CancellationToken cancellationToken) { var brand = _mapper.Map <Domain.Model.Brand.Brand>(request.CreateBrandDto); await _brandRepository.AddAsync(brand); await _brandRepository.Context.SaveChangesAsync(); }
public async Task <IActionResult> Post(BrandIndexViewModel model) { var brand = new Brand { Id = model.Id, Name = model.Name, Description = model.Description }; await _brandRepository.AddAsync(brand); TempData["SM"] = "Вы успешно создали."; return(RedirectToAction("Index", "Brand")); }
public async Task <IActionResult> Save(int?id, string title, string slug, State state, IFormFile photo) { if (id == null) { //To do: Add Brand var brand = new Brand { CreateDate = DateTime.UtcNow, Title = title, Slug = slug, Creator = Operator, State = state, }; await _repo.AddAsync(brand); await _repo.SaveAsync(); if (photo != null) { var brandId = brand.Id;//for name =>1.jpg var ext = Path.GetExtension(photo.FileName); var path = Path.Combine(_env.WebRootPath + "\\Images\\Brands", brandId + ext); using (var filestream = new FileStream(path, FileMode.Create)) { await photo.CopyToAsync(filestream); } } return(RedirectToAction("list")); } else { var brand = await _repo.GetBrandAsync(id.Value); brand.State = state; brand.Slug = slug; brand.Title = title; brand.LastModifier = Operator; brand.LastModifyDate = DateTime.UtcNow; await _repo.Update(brand); await _repo.SaveAsync(); } return(View()); }
public IActionResult Create([FromBody] Brand brand) { var result = brandRepository.AddAsync(brand).Result; return(Ok(result)); }
public async Task AddAsync(BrandDto obj) => await _repository.AddAsync(_mapper.Map <BrandDto, Brand>(obj));
public async Task <dynamic> AddAsync(Brand brand) { brand.CreatedDate = DateTime.Now; brand.ModifiedDate = DateTime.Now; return(new { succeeded = true, data = await _brandRepository.AddAsync(brand) }); }