Example #1
0
        public async Task CreateAsync(CreateVendorsViewModel input)
        {
            var vendor = new Vendor()
            {
                Name      = input.Name,
                Trade     = input.Trade,
                Phone     = input.Phone,
                Email     = input.Email,
                ManagerId = input.ManagerId,
            };

            await this.vendorsRepository.AddAsync(vendor);

            await this.vendorsRepository.SaveChangesAsync();
        }
        public async Task CreateShouldSucceed()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateVendorTestDb").Options;

            using var dbContext        = new ApplicationDbContext(options);
            using var vendorRepository = new EfDeletableEntityRepository <Vendor>(dbContext);
            var vendorsService = new VendorsService(vendorRepository);

            var model = new CreateVendorsViewModel()
            {
                Name = "Best Plumbing",
            };

            await vendorsService.CreateAsync(model);

            var createdModel = dbContext.Vendors.FirstOrDefault(p => p.Name == "Best Plumbing");

            Assert.NotNull(createdModel);
        }
Example #3
0
        public async Task <IActionResult> CreateAsync(CreateVendorsViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            input.ManagerId = this.HttpContext.User.Claims.First(c => c.Type.Contains("nameidentifier")).Value;

            try
            {
                await this.vendorsService.CreateAsync(input);

                return(this.Redirect("/"));
            }
            catch (Exception ex)
            {
                return(this.View("Error", new ErrorViewModel {
                    RequestId = ex.Message
                }));
            }
        }
 public Task CreateAsync(CreateVendorsViewModel model)
 {
     throw new NotImplementedException();
 }