Exemplo n.º 1
0
 public string CreateGroup(GroupViewModel viewModel)
 {
     var group = new Group
     {
         Description = viewModel.Description,
         FestivalId = viewModel.FestivalId,
         FestivalName = viewModel.FestivalName,
         GroupName = viewModel.GroupName,
         GroupSize = viewModel.GroupSize,
         LimitDate = viewModel.LimitDate,
         RoomBooked = !string.IsNullOrEmpty(viewModel.RoomId),
         RoomId = viewModel.RoomId,
         TransportBooked = viewModel.HasTransport
     };
     var groups = new List<Group> {@group};
     var admin = new Member
     {
         EmailAddress = viewModel.Email,
         Groups = groups
     };
     var party = new Party {GroupInfo = group, Leader = admin, Password = viewModel.Password};
     if (_context.Groups.Any(e=>e.GroupName.Equals(group.GroupName)))
     {
         return "A group with that name allready exists";
     }
     if (!_context.Members.Any(e => e.EmailAddress.Equals(admin.EmailAddress)))
     {
         _context.Members.Add(admin);
     }
     _context.Groups.Add(group);
     _context.Parties.Add(party);
     _context.SaveChanges();
     return null;
 }
Exemplo n.º 2
0
 protected bool Equals(Member other)
 {
     return string.Equals(EmailAddress, other.EmailAddress);
 }
Exemplo n.º 3
0
 public string JoinParty(int partyId, string email)
 {
     var party = _context.Parties.FirstOrDefault(e => e.PartyId.Equals(partyId));
     if (party == null)
     {
         return "Party does not exist";
     }
     var member = _context.Members.FirstOrDefault(e => e.EmailAddress.Equals(email));
     if (member == null)
     {
         member = new Member {EmailAddress = email, Groups = new List<Group>()};
         _context.Members.Add(member);
     }
     if (party.PartyMembers.Count >= party.GroupInfo.GroupSize)
     {
         return "Party is full";
     }
     member.Groups.Add(party.GroupInfo);
     party.PartyMembers.Add(member);
     _context.SaveChanges();
     return null;
 }