Exemplo n.º 1
0
        /// <summary>
        /// GET /events/{id}. 
        /// • retrieves the profile of an individual Event
        /// • "id" is Event.id
        /// • authentication is required if this is not a public event - user must then be admin,
        /// member or follower
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Events(int? id)
        {
            #region initial steps
            Response.ContentType = Assistant.JsonMimeType;
            if (!CheckAuthentication(UserRole.Any))
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return Json(Assistant.ErrorUnauthorized, JsonRequestBehavior.AllowGet);
            }
            #endregion

            JsonResult jr;
            SedogoEvent sevent;
            int? e = PrepareForEvent(id, out jr, out sevent);
            if (!e.HasValue)
                return jr;

            //everything is fine, let's create a model and return it in JSON
            var model = new EventModel {
                id = sevent.eventID,
                created = sevent.createdDate,
                updated = sevent.lastUpdatedDate,
                name = sevent.eventName,
                user = sevent.userID,
                venue = sevent.eventVenue,
                description = sevent.eventDescription,
                mustDo = sevent.mustDo,
                dateType = sevent.dateType,
                start = (sevent.startDate.Ticks>0)?sevent.startDate : (DateTime?)null,
                rangeStart = (sevent.rangeStartDate.Ticks>0)?sevent.rangeStartDate:(DateTime?)null,
                rangeEnd = (sevent.rangeEndDate.Ticks>0)?sevent.rangeEndDate:(DateTime?)null,
                beforeBirthday = (sevent.beforeBirthday),   //optional!!!
                achieved = sevent.eventAchieved,
                Private = sevent.privateEvent,
                category = sevent.categoryID,   //optional!!
                createdFromEvent = sevent.createdFromEventID, //optional!!
                timezone = sevent.timezoneID,
                image = sevent.eventPicFilename,
                imageThumbnail = sevent.eventPicThumbnail,
                imagePreview = sevent.eventPicPreview

            };
            return Json(model.GetDetails(), JsonRequestBehavior.AllowGet);
        }