public void Remove_SubEntity_Detached() { User userWithGroups; using (var context = new MeetupContext()) { var tmpUser = _context.Users .Include(x => x.Groups) .ThenInclude(x => x.Group) .First(x => x.Id == 1); tmpUser.Groups.Add(new UserGroup { UserId = tmpUser.Id, GroupId = 1 }); context.SaveChanges(); userWithGroups = _context.Users .Include(x => x.Groups) .ThenInclude(x => x.Group) .First(x => x.Id == 1); } var group = userWithGroups.Groups.FirstOrDefault(); userWithGroups.Groups.Remove(group); _context.Attach(userWithGroups); _context.SaveChanges(); }
public void Change_Object_One_To_Another_Without_Tracking() { using (var context = new MeetupContext()) { var german = context.Users.Include(x => x.Profile).First(x => x.Email == "*****@*****.**"); german.Profile = new Profile { Twitter = "Twiiter Test 1" }; context.SaveChanges(); } User userWithoutTracking; using (var context = new MeetupContext()) { userWithoutTracking = context.Users.Include(x => x.Profile).First(x => x.Email == "*****@*****.**"); } userWithoutTracking.Profile = new Profile { Twitter = "New Twitter", User = userWithoutTracking }; _context.Users.Attach(userWithoutTracking); Action act = () => _context.SaveChanges(); act.Should().Throw <DbUpdateException>(); }
public void Add_New_UserGroup_With_New_Group() { User user; using (var context = new MeetupContext()) { user = context.Users.First(); } var newGroup = new Group { Name = "MeetupJs", Description = "Meetup sobre JS" }; var userGroup = new UserGroup { Group = newGroup }; user.Groups.Add(userGroup); _context.Users.Attach(user); _context.ChangeTracker.DetectChanges(); _context.SaveChanges(); _context.Remove(userGroup); _context.Remove(newGroup); _context.SaveChanges(); }
private void RunMigrations(MeetupContext context) { var pendingMigrations = context.Database.GetPendingMigrations(); if (pendingMigrations.Any()) { context.Database.Migrate(); } }
public RegisterUserValidator(MeetupContext meetupContext) { RuleFor(x => x.Email).NotEmpty(); RuleFor(x => x.Password).MinimumLength(6); RuleFor(x => x.Password).Equal(x => x.ConfirmPassword); RuleFor(x => x.Email).Custom((value, context) => { var userAlreadyExists = meetupContext.Users.Any(user => user.Email == value); if (userAlreadyExists) { context.AddFailure("Email", "That Email address is taken!!"); } }); }
public ActionResult Delete(string name) { var meetup = MeetupContext.Meetups .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == name.Replace(" ", "-").ToLower()); if (meetup == null) { return(NotFound()); } MeetupContext.Remove(meetup); MeetupContext.SaveChanges(); return(NoContent()); }
public ActionResult Delete(string meetupName) { var meetup = MeetupContext.Meetups .Include(m => m.Lectures) .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == meetupName.Replace(" ", "-").ToLower()); if (meetup == null) { return(NotFound()); } MeetupContext.Lectures.RemoveRange(meetup.Lectures); MeetupContext.SaveChanges(); return(NoContent()); }
public RegisterUserValidator(MeetupContext meetupContext) { RuleFor(x => x.Email).NotEmpty(); RuleFor(x => x.Password).NotEmpty(); RuleFor(x => x.ConfirmPassword).NotEmpty(); RuleFor(x => x.Email).Custom((value, context) => { var userAlreadyExist = meetupContext.Users.Any(u => u.Email == value); if (userAlreadyExist) { context.AddFailure("Email", "That email address is taken"); } }); RuleFor(x => x.Password).MinimumLength(6); RuleFor(x => x.Password).Equal(x => x.ConfirmPassword).WithMessage("Password must be equal to Confirm Password"); }
public RegisterUserValidator(MeetupContext meetupContext) { _meetupContext = meetupContext; RuleFor(x => x.Email).NotEmpty(); RuleFor(x => x.Password).MinimumLength(6); RuleFor(x => x.ConfirmPassword).Equal(x => x.Password); RuleFor(x => x.Email).Custom((value, context) => { var userExists = _meetupContext.Users.Any(u => u.Email == value); if (userExists) { context.AddFailure("Email", "That email address has been taken"); } }); }
public ActionResult Post([FromBody] MeetupDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); // does Required field are valid and mindlenght in MeetupDto } var meetup = Mapper.Map <Meetup>(model); // map model on Meetup MeetupContext.Meetups.Add(meetup); MeetupContext.SaveChanges(); var key = meetup.Name.Replace(" ", "-").ToLower(); return(Created("api/meetups/" + key, null)); }
public void Remove_User_Group_In_Memory() { using (var context = new MeetupContext()) { var user = context.Users.First(); var group = context.Groups.First(); var userGroup = new UserGroup { Group = group, User = user }; user.Groups.Add(userGroup); context.SaveChanges(); } _context.Remove(new UserGroup { UserId = 1, GroupId = 1 }); _context.SaveChanges(); }
public void Add_New_User_Group_Detached_Entity() { User user; using (var context = new MeetupContext()) { user = context.Users.First(); } var userGroup = new UserGroup { GroupId = 1 }; user.Groups.Add(userGroup); _context.Users.Attach(user); _context.ChangeTracker.DetectChanges(); _context.SaveChanges(); _context.Remove(userGroup); _context.SaveChanges(); }
public ActionResult Put(string name, [FromBody] MeetupDto model) { var meetup = MeetupContext.Meetups .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == name.Replace(" ", "-").ToLower()); if (meetup == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); // does Required field are valid and mindlenght in MeetupDto } meetup.Name = model.Name; meetup.Organizes = model.Organizes; meetup.Date = model.Date; meetup.IsPrivate = model.IsPrivate; MeetupContext.SaveChanges(); return(NoContent()); }
public ActionResult Post(string meetupName, [FromBody] LectureDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); // does Required field are valid and mindlenght in MeetupDto } var meetup = MeetupContext.Meetups .Include(m => m.Lectures) .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == meetupName.Replace(" ", "-").ToLower()); if (meetup == null) { return(NotFound()); } var lecture = Mapper.Map <Lecture>(model); meetup.Lectures.Add(lecture); MeetupContext.SaveChanges(); return(Created($"api/meetups/{meetupName}", null)); }
public MeetupController(MeetupContext meetupContext, IMapper mapper, IAuthorizationService authorizationService) { _meetupContext = meetupContext; _mapper = mapper; _authorizationService = authorizationService; }
public MeetupSeeder(MeetupContext meetupContext) { _meetupContext = meetupContext; }
public EncapsulateCollectionsShould() { _context = new MeetupContext(); }
public ShadowPropertyShould() { _context = new MeetupContext(); }
public LectureController(MeetupContext meetupContext, IMapper mapper, ILogger <LectureController> logger) { _meetupContext = meetupContext; _mapper = mapper; _logger = logger; }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MeetupContext( serviceProvider.GetRequiredService < DbContextOptions <MeetupContext> >())) { // Look for any movies. if (context.Person.Any()) { return; // DB has been seeded } context.Person.AddRange( new Person { FirstName = "Alan", LastName = "Nash", Birthday = DateTime.Parse("1962-06-16"), Interest = "Golf" }, new Person { FirstName = "Gertrude", LastName = "Valdez", Birthday = DateTime.Parse("1973-04-22"), Interest = "Volleyball" }, new Person { FirstName = "Gina", LastName = "Bishop", Birthday = DateTime.Parse("1979-04-02"), Interest = "Soccer" }, new Person { FirstName = "Jeremy", LastName = "Lynch", Birthday = DateTime.Parse("1982-08-21"), Interest = "Golf" }, new Person { FirstName = "Lionel", LastName = "Caldwell", Birthday = DateTime.Parse("1984-04-11"), Interest = "Volleyball" }, new Person { FirstName = "Alberta", LastName = "Drake", Birthday = DateTime.Parse("1989-06-22"), Interest = "Hiking" }, new Person { FirstName = "Kelli", LastName = "Simon", Birthday = DateTime.Parse("1990-12-30"), Interest = "Golf" }, new Person { FirstName = "Alice", LastName = "Shelton", Birthday = DateTime.Parse("1995-05-30"), Interest = "Hiking" }, new Person { FirstName = "Delia", LastName = "Mcdonald", Birthday = DateTime.Parse("1997-04-03"), Interest = "Volleyball" }, new Person { FirstName = "Rudy", LastName = "Curry", Birthday = DateTime.Parse("2000-02-25"), Interest = "Soccer" } ); context.SaveChanges(); } }
public ManyToManyShould() { _context = new MeetupContext(); }
public MeetupController(MeetupContext meetupContext) { _meetupContext = meetupContext; }
public AccountController(MeetupContext meetupContext, IPasswordHasher <User> passwordHasher, IJwtProvider jwtProvider) { _meetupContext = meetupContext; _passwordHasher = passwordHasher; _jwtProvider = jwtProvider; }
public OneToOneRelationshipsShould() { _context = new MeetupContext(); }
public TestController(MeetupContext meetupContext, IMath mathService) { _meetupContext = meetupContext; _mathService = mathService; }
public LectureController(MeetupContext meetupContext, IMapper mapper) { MeetupContext = meetupContext; Mapper = mapper; }
public PeopleController(MeetupContext context) { _context = context; }
public MeetupController(MeetupContext meetupContext, IMapper mapper) { _meetupContext = meetupContext; _mapper = mapper; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MeetupSeeder meetupSeeder, MeetupContext context) { RunMigrations(context); app.UseResponseCaching(); app.UseStaticFiles(); app.UseCors("FrontEndClient"); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "MeetupAPI v1"); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseAuthentication(); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); meetupSeeder.Seed(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MeetupSeeder meetupSeeder, MeetupContext context) { RunMigrations(context); app.UseResponseCaching(); app.UseStaticFiles(); app.UseCors("FrontEndClient"); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "MeetupAPI v1"); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseAuthentication(); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); meetupSeeder.Seed(); }