public async Task <ValidationResultModel> ValidateAsync(Guid orgId, ProductBrandDto model) { // Reset validation errors model.Errors.Clear(); #region Formatting: Cleansing and formatting model.Code = model.Code.ToUpper(); model.Name = model.Name.TrimExtraSpaces(); model.Description = model.Description.TrimExtraSpaces(); #endregion #region Validation: Duplicate // Check code duplicate var duplCode = new Duplicate { Field = DuplicateField.Code, Value = model.Code, Id = model.Id, ParentId = orgId }; if (await ExistsAsync(duplCode)) { model.Errors.AddError(nameof(model.Code), $"{nameof(model.Code)} '{model.Code}' already exists"); } // Check name duplicate var duplName = new Duplicate { Field = DuplicateField.Name, Value = model.Name, Id = model.Id, ParentId = orgId }; if (await ExistsAsync(duplName)) { model.Errors.AddError(nameof(model.Name), $"{nameof(model.Name)} '{model.Name}' already exists"); } #endregion return(model.Errors); }
public static ProductBrandCommand ToCommand(this ProductBrandDto brand) { return(new ProductBrandCommand { Name = brand.Name, Picture = brand.Icon != null?brand.Icon.ToCommand() : new PictureCommand() }); }
public async Task UpdateAsync(Guid id, ProductBrandDto model) { if (id != model.Id) { throw new ArgumentException("Product brand id mismatch"); } var item = _mapper.Map <ProductBrand>(model); item.DateModified = DateTime.UtcNow; _context.ProductBrands.Update(item); await _context.SaveChangesAsync(); //return _mapper.Map<ProductBrandDto>(item); }
public async Task <ProductBrandDto> CreateAsync(Guid orgId, ProductBrandDto model) { if (orgId == null || orgId == Guid.Empty) { throw new ArgumentNullException("orgId", "Org id is missing"); } var item = _mapper.Map <ProductBrand>(model); item.OrgId = orgId; item.DateCreated = DateTime.UtcNow; item.DateModified = null; await _context.ProductBrands.AddAsync(item); await _context.SaveChangesAsync(); return(_mapper.Map <ProductBrandDto>(item)); }
public async Task <ProductBrand> GetProductBrandAsync(int id) { ProductBrandDto productBrandDto = await _productBrandStorage.GetByIdAsync(id); return(productBrandDto?.ToCoreEntity()); }