public ActionResult GetPartyById(Guid?id)
        {
            try
            {
                //List<JObject> jsonList = new List<JObject>();

                var singleParty = _dbContext.PartyItems
                                  .Include(p => p.Location)
                                  .Include(p => p.Host)
                                  .First <Party>(p => p.PartyId == id);

                if (singleParty == null)
                {
                    return(NotFound());
                }
                else
                {
                    //jsonList.Add(AddCustomJson(singleParty));
                    JObject partyJObject = new AddPartyJSON(_dbContext, User).AddCustomJson(singleParty);
                    return(Ok(partyJObject));
                }
            }
            catch (Exception)
            {
                return(NotFound("Party not found."));
            }
        }
Exemplo n.º 2
0
        public ActionResult GetPartys(Boolean loadAll = false)
        {
            List <JObject> jsonList = new List <JObject>();
            List <Party>   partys;

            if (!loadAll)
            {
                //Select parties in future
                partys = _dbContext.PartyItems
                         .Where(p => p.PartyDate.Date >= DateTime.Today)
                         .Include(p => p.Location)
                         .Include(p => p.Host)
                         .ToList();
            }
            else
            {
                //Select all parties
                partys = _dbContext.PartyItems
                         .Include(p => p.Location)
                         .Include(p => p.Host)
                         .ToList();
            }

            if (partys == null)
            {
                return(NotFound("There are no partys."));
            }
            else
            {
                partys = partys.OrderByDescending(p => p.PartyDate).ToList();
                foreach (Party singleParty in partys)
                {
                    //Location + Host not as array
                    JObject tempJobject = new JObject();
                    tempJobject = new AddPartyJSON(_dbContext, User).AddCustomJsonForAdmin(singleParty);
                    tempJobject.Remove("MusicGenre");
                    tempJobject.Add("MusicGenre", singleParty.MusicGenre.ToString());
                    tempJobject.Remove("PartyType");
                    tempJobject.Add("PartyType", singleParty.PartyType.ToString());
                    tempJobject.Remove("CommittedUser");
                    tempJobject.Remove("Location");
                    tempJobject.Remove("Host");
                    string locationString = singleParty.Location.StreetName + " " + singleParty.Location.HouseNumber + ", " + singleParty.Location.Zipcode + " " + singleParty.Location.CityName + ", " + singleParty.Location.CountryName;
                    tempJobject.Add("Location", locationString);
                    string hostString = singleParty.Host.UserName + " " + singleParty.Host.Email;
                    tempJobject.Add("Host", hostString);

                    jsonList.Add(tempJobject);
                }
            }
            return(Ok(jsonList));
        }