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
 public HttpResponseMessage Post(GroupViewModel viewModel)
 {
     using (var provider = new Provider())
     {
         var result = provider.EditGroup(viewModel);
         return new HttpResponseMessage
         {
             Content = new JsonContent(result)
         };
     }
 }
Exemplo n.º 3
0
 public string EditGroup(GroupViewModel viewModel)
 {
     var group = _context.Groups.FirstOrDefault(e => e.GroupId.Equals(viewModel.GroupId));
     if (group == null)
     {
         return "Group does not exist";
     }
     foreach (Group groupToCompare in _context.Groups)
     {
         if (ComapreGroups(viewModel, groupToCompare))
         {
             return "A group with this name allready exists";
         }
     }
     group.Description = viewModel.Description;
     group.FestivalId = viewModel.FestivalId;
     group.FestivalName = viewModel.FestivalName;
     group.GroupName = viewModel.GroupName;
     group.GroupSize = viewModel.GroupSize;
     group.LimitDate = viewModel.LimitDate;
     group.RoomBooked = !string.IsNullOrEmpty(viewModel.RoomId);
     group.RoomId = viewModel.RoomId;
     group.TransportBooked = viewModel.HasTransport;
     _context.SaveChanges();
     return null;
 }
Exemplo n.º 4
0
 private static bool ComapreGroups(GroupViewModel viewModel, Group existingGroup)
 {
     return existingGroup.GroupName.Equals(viewModel.GroupName) && !existingGroup.GroupId.Equals(viewModel.GroupId) &&
            existingGroup.FestivalName.Equals(viewModel.FestivalName);
 }