Example #1
0
        public async Task CreateAsync(CreateLicenseViewModel model)
        {
            var entity = new License()
            {
                Name = model.Name, Description = model.Description
            };

            await this.licensesRepository.AddAsync(entity);

            await this.licensesRepository.SaveChangesAsync();
        }
        public void Create_ShouldExecuteSuccessfully()
        {
            var model = new CreateLicenseViewModel()
            {
                Name        = "test",
                Description = "test",
            };

            var list = new List <License>();

            var repo    = DeletableEntityRepositoryMock.Get <License>(list);
            var service = new LicenseService(repo.Object);

            service.CreateAsync(model).Wait();

            Assert.Single(list);
        }
        public IActionResult Create(CreateLicenseViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            try
            {
                this.licenseService.CreateAsync(model);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View(model));
            }

            return(this.RedirectToAction("Index", "Licenses"));
        }