public void Create_New_UserGroup()
        {
            var userGroup = new UserGroup {
                UserId = 1, GroupId = 1
            };

            _context.Add(userGroup);
            _context.SaveChanges();

            _context.Remove(userGroup);
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public ActionResult Post([FromBody] MeetupDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var meetup = _mapper.Map <Meetup>(model);

            _meetupContext.Add(meetup);
            _meetupContext.SaveChanges();
            var key = meetup.Name.Replace(" ", "-").ToLower();

            return(Created("api/meetup/" + key, null));
        }
Ejemplo n.º 3
0
        public ActionResult Post([FromBody] MeetupDto newMeetup)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }

            var meetup = _mapper.Map <Meetup>(newMeetup);

            _meetupContext.Meetups.Add(meetup);
            _meetupContext.SaveChanges();

            return(Created($"szym/meetup/{meetup.Name.Replace(" ", "-").ToLower()}", null));
        }
Ejemplo n.º 4
0
        public void Crete_New_MeetupEvent_Add_Assistants()
        {
            var meetupEvent = new MeetupEvent();

            _context.Add(meetupEvent);
            _context.SaveChanges();

            meetupEvent.AddAssistant(_context.Users.First());
            _context.SaveChanges();

            meetupEvent.Assistants.Count().Should().Be(1);

            _context.Remove(meetupEvent);
            _context.SaveChanges();
        }
Ejemplo n.º 5
0
        public void Crete_New_MeetupEvent_Add_Assistants()
        {
            //TODO: 04 - Creo un nuevo evento y le agrego un asistente
            var meetupEvent = new MeetupEvent();

            _context.Add(meetupEvent);
            _context.SaveChanges();

            meetupEvent.AddAssistant(_context.Users.First());
            _context.SaveChanges();

            meetupEvent.Assistants.Count().Should().Be(1);

            _context.Remove(meetupEvent);
            _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>();
        }
Ejemplo n.º 7
0
        public ActionResult Register([FromBody] RegisterUserDto registerUserDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            var newUser = new User()
            {
                Email       = registerUserDto.Email,
                Nationality = registerUserDto.Nationality,
                DateOfBirth = (DateTime)registerUserDto.DateOfBirth,
                RoleId      = registerUserDto.RoleId
            };

            var passwordHash = _passwordHasher.HashPassword(newUser, registerUserDto.Password);

            newUser.PasswordHash = passwordHash;

            _meetupContext.Users.Add(newUser);
            _meetupContext.SaveChanges();
            return(Ok());
        }
Ejemplo n.º 8
0
        private void InsertSampleData()
        {
            var meetups = new List <Meetup>
            {
                new Meetup
                {
                    Name      = "Web summit",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "Microsoft",
                    Location  = new Location
                    {
                        City     = "Krakow",
                        Street   = "Szeroka 33/5",
                        PostCode = "31-337"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Bob Clark",
                            Topic       = "Modern browsers",
                            Description = "Deep dive into V8"
                        }
                    }
                },

                new Meetup
                {
                    Name      = "4Devs",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "KGD",
                    Location  = new Location
                    {
                        City     = "Warszsawa",
                        Street   = "Chmielna 33/5",
                        PostCode = "00-007"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Will Smith",
                            Topic       = "React.js",
                            Description = "Redux introduction"
                        },
                        new Lecture
                        {
                            Author      = "John Cena",
                            Topic       = "Angular store",
                            Description = "Ngxs in practise"
                        }
                    }
                },
            };

            _meetupContext.AddRange(meetups);
            _meetupContext.SaveChanges();
        }
Ejemplo n.º 9
0
        public void Throw_Exception_About_Required_ShadowProperty()
        {
            //TODO: 02 - Inserto una entidad con shadow property requerida en null
            var eventMeetup = new MeetupEvent(DateTime.Now.AddDays(5), DateTime.Now.AddDays(5));

            _context.Meetups.Add(eventMeetup);

            var timesTamp = DateTime.Now;

            _context.Entry(eventMeetup).Property("Created").CurrentValue      = null;
            _context.Entry(eventMeetup).Property("LastModified").CurrentValue = timesTamp;

            Action act = () => _context.SaveChanges();

            act.Should().Throw <InvalidOperationException>();
        }
Ejemplo n.º 10
0
        private void InsertSimpleData()
        {
            var meetups = new List <Meetup>
            {
                new Meetup
                {
                    Name      = "Web Submit",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "Microsoft",
                    Location  = new Location()
                    {
                        City     = "Nowa Sól",
                        Street   = "Matejki 22",
                        PostCode = "67-100"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Bob Clark",
                            Topic       = "Modern Browsers",
                            Description = "Deep dive into V8"
                        }
                    }
                },

                new Meetup
                {
                    Name      = "4Devs",
                    Date      = DateTime.Now.AddDays(3),
                    IsPrivate = false,
                    Organizer = "Microsoft",
                    Location  = new Location()
                    {
                        City     = "Wroclaw",
                        Street   = "Matejki 22",
                        PostCode = "00-007"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Bob Clark",
                            Topic       = "Modern Browsers",
                            Description = "Deep dive into V10 Porsche"
                        },
                        new Lecture
                        {
                            Author      = "Lukasz Zietek",
                            Topic       = "Swiat i Kredki",
                            Description = "Wejscie w swiat 5G"
                        }
                    }
                }
            };

            _meetupContext.AddRange(meetups);
            _meetupContext.SaveChanges();
        }
        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();
        }
Ejemplo n.º 12
0
        public ActionResult Delete(string meetupName)
        {
            Meetup meetup = _meetupContext.Meetups
                            .Include(m => m.Lectures)
                            .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == meetupName.ToLower());

            if (meetup == null)
            {
                return(NotFound());
            }

            _meetupContext.Lectures.RemoveRange(meetup.Lectures);
            _meetupContext.SaveChanges();

            return(NoContent());
        }
Ejemplo n.º 13
0
        private void InsertSampleData()
        {
            var meetups = new List <Meetup>
            {
                new Meetup
                {
                    Name      = "Web summit",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "Mircosoft",
                    Location  = new Location
                    {
                        City     = "HCM",
                        Street   = "Cach Mang Thang 8",
                        PostCode = "71234"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Duy Hoang",
                            Topic       = "Modern browsers",
                            Description = "Deep live into V8"
                        }
                    }
                },
                new Meetup
                {
                    Name      = "4Devs",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "KGD",
                    Location  = new Location
                    {
                        City     = "HCM",
                        Street   = "Thong nhat",
                        PostCode = "70007"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Hoang Tran",
                            Topic       = "react.js",
                            Description = "new technical"
                        },
                        new Lecture
                        {
                            Author      = "Johnny",
                            Topic       = "angular.js",
                            Description = "new frontend technical"
                        }
                    }
                }
            };

            _meetupContext.AddRange(meetups);
            _meetupContext.SaveChanges();
        }
Ejemplo n.º 14
0
        private void InsertsampleData()
        {
            var meetups = new List <Meetup>

            {
                new Meetup
                {
                    Name      = "Web Summit",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "MS",
                    Location  = new Location
                    {
                        City     = "Belgrade",
                        Street   = "Bulevar Mira 22",
                        PostCode = "11070"
                    },

                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Bob Klark",
                            Topic       = "Browsers",
                            Description = "Dive into V8"
                        }
                    }
                },

                new Meetup
                {
                    Name      = "4Devs",
                    Date      = DateTime.Now.AddDays(10),
                    IsPrivate = false,
                    Organizer = "KGD",
                    Location  = new Location
                    {
                        City     = "Belgrade",
                        Street   = "Bulevar Revolucije 212",
                        PostCode = "11000"
                    },

                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Rob smith",
                            Topic       = ".NET",
                            Description = "Dive into .NET 5"
                        }
                    }
                }
            };


            _meetupContext.AddRange(meetups);
            _meetupContext.SaveChanges();
        }
Ejemplo n.º 15
0
        public ActionResult Post([FromBody] MeetupDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var meetup = _mapper.Map <Meetup>(model);

            var userId = User.FindFirst(c => c.Type == ClaimTypes.NameIdentifier).Value;

            meetup.CreatedById = int.Parse(userId);

            _meetupContext.Meetups.Add(meetup);
            _meetupContext.SaveChanges();
            var key = meetup.Name.Replace(" ", "-").ToLower();

            return(Created($"/api/meetup/{key}", null));
        }
Ejemplo n.º 16
0
        public ActionResult Delete(string meetupName)
        {
            var meetup = _meetupContext.Meetups
                         .Include(m => m.Lectures)
                         .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == meetupName.ToLower());

            if (meetup == null)
            {
                return(NotFound());
            }

            _logger.LogWarning($"Wykłady dla meetup {meetup.Name} zostały usunięte");

            _meetupContext.Lectures.RemoveRange(meetup.Lectures);
            _meetupContext.SaveChanges();

            return(NoContent());
        }
Ejemplo n.º 17
0
        private void InsertSampleData()
        {
            var meetups = new List <Meetup>
            {
                new Meetup
                {
                    Name      = "Web submit",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "Microsoft",
                    Location  = new Location
                    {
                        City     = "Prague",
                        Street   = "Laubova 33",
                        PostCode = "00100"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Bob Clark",
                            Topic       = "Modern Browsers",
                            Description = "Deep dove into V8"
                        }
                    }
                },
                new Meetup
                {
                    Name      = "4Devs",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Organizer = "KGD",
                    Location  = new Location
                    {
                        City     = "Warszaw",
                        Street   = "Chmielna 33/5",
                        PostCode = "00-007"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Will Smith",
                            Topic       = "1000 words",
                            Description = "Budhism"
                        }
                    }
                },
            };



            _meetupContext.AddRange(meetups);
            _meetupContext.SaveChanges();
        }
Ejemplo n.º 18
0
        public ActionResult Post(string meetupName, [FromBody] LectureDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var meetup = _meetupContext.Meetups
                         .Include(m => m.Lectures)
                         .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == meetupName.ToLower());

            if (meetup is null)
            {
                return(NotFound());
            }
            var lecture = _mapper.Map <Lecture>(model);

            meetup.Lectures.Add(lecture);
            _meetupContext.SaveChanges();
            return(Created($"api/meetup/{meetupName}", null));
        }
Ejemplo n.º 19
0
        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 void Add_Founder_To_Group_Through_User_Fk()
        {
            var netBaires = GetGroup();

            var german = _context.Users.First(x => x.Email == "*****@*****.**");

            netBaires.AddFounder(german);

            _context.SaveChanges();

            netBaires = GetGroup();

            netBaires.Founder.Should().Be(german);

            netBaires.SetFreeGroup(german);
            _context.SaveChanges();
        }
Ejemplo n.º 21
0
        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();
        }
Ejemplo n.º 23
0
        public ActionResult Delete(string meetupName, int id)
        {
            var meetup = MeetupContext.Meetups
                         .Include(m => m.Lectures)
                         .FirstOrDefault(m => m.Name.Replace(" ", "-").ToLower() == meetupName.Replace(" ", "-").ToLower());

            if (meetup == null)
            {
                return(NotFound());
            }

            var lecture = meetup.Lectures.FirstOrDefault(l => l.Id == id);

            if (lecture == null)
            {
                return(NotFound());
            }

            MeetupContext.Lectures.Remove(lecture);
            MeetupContext.SaveChanges();
            return(NoContent());
        }
Ejemplo n.º 24
0
        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());
        }
Ejemplo n.º 25
0
        private void InsertSampleData()
        {
            var meetups = new List <Meetup>
            {
                new Meetup
                {
                    Name      = "First meet up",
                    Organizer = "Alice",
                    Date      = DateTime.Now.AddDays(7),
                    IsPrivate = false,
                    Location  = new Location
                    {
                        City     = "Auckland",
                        Street   = "Mount Street",
                        PostCode = "1010",
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Tom",
                            Topic       = "Art",
                            Description = "A lecture on art"
                        },
                        new Lecture
                        {
                            Author      = "Jerry",
                            Topic       = "Math",
                            Description = "A lecture on math"
                        }
                    }
                },
                new Meetup
                {
                    Name      = "Second meet up",
                    Organizer = "Bob",
                    Date      = DateTime.Now.AddDays(14),
                    IsPrivate = true,
                    Location  = new Location
                    {
                        City     = "Wellington",
                        Street   = "Sussex Street",
                        PostCode = "6100",
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "Wang",
                            Topic       = "Art",
                            Description = "A lecture on art"
                        },
                        new Lecture
                        {
                            Author      = "Zhang",
                            Topic       = "Math",
                            Description = "A lecture on math"
                        }
                    }
                },
            };

            _meetupContext.AddRange(meetups);
            _meetupContext.SaveChanges();
        }
Ejemplo n.º 26
0
        private void InsertSampleData()
        {
            var meetups = new List <Meetup>
            {
                new Meetup
                {
                    Name      = "M 1",
                    Date      = DateTime.Now.AddDays(15),
                    IsPrivate = false,
                    Organizer = "O1",
                    Location  = new Location
                    {
                        City       = "Prze",
                        Street     = "Long",
                        PostalCode = "00-111"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "A1.1",
                            Topic       = "T1.1",
                            Description = "Desc1.1"
                        },
                        new Lecture
                        {
                            Author      = "A1.2",
                            Topic       = "T1.2",
                            Description = "Desc1.2"
                        }
                    }
                },
                new Meetup
                {
                    Name      = "M2",
                    Date      = DateTime.Now.AddDays(35),
                    IsPrivate = true,
                    Organizer = "O2",
                    Location  = new Location
                    {
                        City       = "Strze",
                        Street     = "Short",
                        PostalCode = "11-000"
                    },
                    Lectures = new List <Lecture>
                    {
                        new Lecture
                        {
                            Author      = "A2.1",
                            Topic       = "T2.1",
                            Description = "Desc2.1"
                        },
                        new Lecture
                        {
                            Author      = "A2.2",
                            Topic       = "T2.2",
                            Description = "Desc2.2"
                        }
                    }
                }
            };

            _meetupContext.AddRange(meetups);
            _meetupContext.SaveChanges();
        }
Ejemplo n.º 27
0
        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();
            }
        }