public HttpResponseMessage DeleteEducation(EducationModel model) { IUnitOfWork uWork = new UnitOfWork(); IEducationRepository education = new EducationRepository(uWork); IEducationService educationService = new EducationService(education); try { if (this.ModelState.IsValid) { var result = educationService.DeleteEducation(model); if (result != null) { return(Request.CreateResponse(HttpStatusCode.OK, result)); } else { string message = "Not deleted successfully"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public IHttpActionResult DeleteEducation(long educationId) { try { return(Ok(_educationService.DeleteEducation(educationId))); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void DeleteEducationShouldDeleteAnEducationFromDatabase() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options; var dbContext = new ApplicationDbContext(options); var service = new EducationService(dbContext); dbContext.Educations.Add(new Education()); dbContext.Educations.Add(new Education()); dbContext.Educations.Add(new Education()); dbContext.SaveChanges(); var education = dbContext.Educations.First(); service.DeleteEducation(education); Assert.Equal(2, dbContext.Educations.Count()); }
public void DeleteEducation_Pass() { using (ApplicationDbContext context = new ApplicationDbContext(Options)) { EducationService educationService = new EducationService(context); UserService userService = new UserService(context); User user = new User { FirstName = "Kyle", LastName = "Burgi" }; userService.AddUser(user); Education edu = new Education { CollegeName = "Eastern Washington University", FieldOfStudy = "Computer Science", UserId = user.Id }; educationService.AddEducation(edu); } using (ApplicationDbContext context = new ApplicationDbContext(Options)) { EducationService educationService = new EducationService(context); educationService.DeleteEducation(1); } using (ApplicationDbContext context = new ApplicationDbContext(Options)) { EducationService educationService = new EducationService(context); UserService userService = new UserService(context); List <User> users = userService.GetBatchUsers(); List <Education> userEdcuation = educationService.GetEducationForUser(users[0].Id); Assert.IsTrue(userEdcuation.Count == 0); } }