private Vendor FindOrCreateVendor(string abbr, IUnitOfWork uow) { if (_vendorAbbr.ContainsKey(abbr)) { if (_vendors == null) { _vendors = uow.VendorRepository.GetAll().ToList(); } var vendor = _vendors.SingleOrDefault(v => v.Name.StartsWith(_vendorAbbr[abbr], true, CultureInfo.InvariantCulture)); if (vendor == null) { vendor = new Vendor { Name = _vendorAbbr[abbr] }; var service = new VendorService(null, uow); service.Create(vendor); _vendors.Add(vendor); } return(vendor); } return(null); }
public async Task <IActionResult> Create(Vendor vendor) { try { var createdVendor = await vendorServ.Create(vendor); return(Ok(createdVendor)); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); return(StatusCode(500)); } }
public async void Create() { var mock = new ServiceMockFacade <IVendorRepository>(); var model = new ApiVendorRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Vendor>())).Returns(Task.FromResult(new Vendor())); var service = new VendorService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VendorModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVendorMapperMock, mock.DALMapperMockFactory.DALVendorMapperMock, mock.BOLMapperMockFactory.BOLProductVendorMapperMock, mock.DALMapperMockFactory.DALProductVendorMapperMock, mock.BOLMapperMockFactory.BOLPurchaseOrderHeaderMapperMock, mock.DALMapperMockFactory.DALPurchaseOrderHeaderMapperMock); CreateResponse <ApiVendorResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.VendorModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVendorRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Vendor>())); }
public ActionResult <Vendor> Create(Vendor vendor) { _vendorService.Create(vendor); return(CreatedAtRoute("GetVendor", new { id = vendor.Id.ToString() }, vendor)); }
public ActionResult <User> CreateVendor(Vendor vendor) { _VendorService.Create(vendor); return(Ok()); }