Example #1
0
        public void EditAsync_ReturnsCorrectNumberOfModifiedEntries()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var dbContext = new ApplicationDbContext(options))
            {
                Qualification qualification = new Qualification()
                {
                    Name = "TestQualification", Description = "random desc"
                };
                EditQualificationServiceModel model = new EditQualificationServiceModel
                {
                    Id   = 1,
                    Name = "NewQualificationName",
                };
                var qualificationsService = new QualificationsService(dbContext);

                dbContext.Qualifications.Add(qualification);
                dbContext.SaveChanges();

                var result = qualificationsService.EditAsync(model);

                Assert.Equal(1, result.Result);
            }
        }
        /// <summary>
        /// Edits the <see cref="Qualification"/> using <see cref="EditQualificationServiceModel"/>.
        /// </summary>
        /// <param name="model">Number of modified entities.</param>
        /// <returns>Service model with <c>Id</c>, <c>Name</c> and <c>Description</c></returns>
        public async Task <int> EditAsync(EditQualificationServiceModel model)
        {
            Qualification qualification = this.dbContext.Qualifications.Find(model.Id);

            qualification.Name        = model.Name;
            qualification.Description = model.Description;

            int modifiedEntities = await this.dbContext.SaveChangesAsync();

            return(modifiedEntities);
        }
Example #3
0
        public async Task <IActionResult> Edit(QualificationInputModel model)
        {
            if (!this.qualificationsService.Exists(model.Id))
            {
                return(this.BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            EditQualificationServiceModel serviceModel = new EditQualificationServiceModel
            {
                Id          = model.Id,
                Name        = model.QualificationName,
                Description = model.Description,
            };

            await this.qualificationsService.EditAsync(serviceModel);

            return(this.RedirectToAction("Details", "Qualifications", new { id = serviceModel.Id }));
        }