// PUT api/<controller>/5
        //
        // Modify existing event
        //
        public HttpResponseMessage Put(int id, [FromBody] JsonEvent value)
        {
            // Make sure the request is valid
            //
            if (string.IsNullOrEmpty(UserId))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Not Authorized"));
            }

            // Update the event
            //
            Repository repository = new Repository();
            Event      iEvent     = repository.GetEventById(id);

            if (iEvent != null)
            {
                iEvent.Name        = value.Name;
                iEvent.Date        = value.Date;
                iEvent.Url         = value.Url;
                iEvent.Location    = value.Location;
                iEvent.Description = value.Description;

                repository.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK, JsonEvent.FromDatabase(iEvent)));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Event not found"));
        }
        // POST api/<controller>
        //
        // Create a new event.  Json eventInfo is passed in through the body of the POST
        //
        public HttpResponseMessage Post([FromBody] JsonEvent eventInfo)
        {
            // Make sure the request is valid
            //
            if (string.IsNullOrEmpty(UserId))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Not Authorized"));
            }

            if (eventInfo == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Invalid Event Information"));
            }

            // Create new Model Event
            //
            RaceDayAPI.Models.Event iEvent = eventInfo.ToDatabase();
            iEvent.GroupId   = GroupId;
            iEvent.CreatorId = UserId;

            // Add to the database and then add this user as a participant
            //
            Repository repository = new Repository();
            Event      newEvent   = repository.AddEvent(iEvent);

            repository.SaveChanges();

            if ((newEvent != null) && (newEvent.EventId > 0))
            {
                var user = repository.GetUserById(UserId);
                repository.AddUserToEvent(user, newEvent, AttendingEnum.Attending);
                repository.SaveChanges();

                var addedEvent     = repository.GetEventViewById(newEvent.EventId, UserId);
                var eventAttendees = repository.GetUsersForEvent(newEvent.EventId);

                // Send an email notification
                //
                var smtp    = new SmtpClient();         // Settings in config file
                var message = new MailMessage("*****@*****.**", ConfigurationManager.AppSettings["AdminEmail"]);
                message.Subject    = "JYMF RaceDay New Event";
                message.IsBodyHtml = true;
                message.Body       = File.ReadAllText(HttpContext.Current.Server.MapPath("~/App_Data/NewEvent.txt"));
                message.Body       = message.Body.Replace("@NAME@", newEvent.Name)
                                     .Replace("@DATE@", newEvent.Date.ToShortDateString())
                                     .Replace("@URL@", newEvent.Url)
                                     .Replace("@LOCATION@", newEvent.Location)
                                     .Replace("@DESCRIPTION@", newEvent.Description)
                                     .Replace("@MFUSER@", this.UserId);

                smtp.Send(message);
                return(Request.CreateResponse(HttpStatusCode.Created, new { eventinfo = addedEvent, attendees = JsonUser.FromDatabase(eventAttendees) }));
            }

            return(Request.CreateResponse(HttpStatusCode.NotAcceptable, "Unable to create event"));
        }