Example #1
0
        public HttpResponseMessage Post([FromBody] SingleSpeakerRequest request)
        {
            HttpResponseMessage response;

            try
            {
                SpeakerEventsResponse speakersResponse = new SpeakerEventsResponse();
                speakersResponse.SpeakerEvents = new ObservableCollection <TechReady.Common.Models.Event>();

                using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
                {
                    var speakers = (from c in ctx.Speakers
                                    where c.SpeakerID == request.SpeakerId
                                    select c).FirstOrDefault();

                    speakersResponse.SpeakerEvents =
                        CreateDxSpeaker(speakers);
                }

                response = this.Request.CreateResponse(HttpStatusCode.OK, speakersResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
        public HttpResponseMessage Post([FromBody] FollowSpeakerRequest request)
        {
            HttpResponseMessage response;
            int appUserId;
            int speakerId;

            try
            {
                FollowSpeakerResponse followSpeakerResponse = new FollowSpeakerResponse();
                appUserId = Convert.ToInt32(request.AppUserId);
                speakerId = Convert.ToInt32(request.SpeakerId);
                using (TechReady.Portal.Models.TechReadyDbContext ctx = new TechReady.Portal.Models.TechReadyDbContext())
                {
                    var appuser = (from c in ctx.AppUsers
                                   where c.AppUserID == appUserId
                                   select c).
                                  FirstOrDefault();

                    if (appuser != null)
                    {
                        var speaker = (from c in ctx.Speakers
                                       where c.SpeakerID == speakerId
                                       select c).FirstOrDefault();

                        if (appuser.FollowedSpeakers == null)
                        {
                            appuser.FollowedSpeakers = new List <Speaker>();
                        }

                        if (request.Follow)
                        {
                            if (speaker != null)
                            {
                                appuser.FollowedSpeakers.Add(speaker);
                            }
                        }
                        else
                        {
                            appuser.FollowedSpeakers.Remove(speaker);
                        }
                        ctx.SaveChanges();
                    }
                }

                response = this.Request.CreateResponse(HttpStatusCode.OK, followSpeakerResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
Example #3
0
        public HttpResponseMessage Post([FromBody] NotificationsRequest request)
        {
            HttpResponseMessage response;

            try
            {
                NotificationsResponse notificationsResponse = new NotificationsResponse();
                notificationsResponse.UserNotifications = new ObservableCollection <TechReady.Common.Models.Notification>();

                using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
                {
                    var appUserId = Convert.ToInt32(request.AppUserId);
                    var appUser   = (from c in ctx.AppUsers
                                     where c.AppUserID == appUserId
                                     select c).FirstOrDefault();

                    if (appUser != null)
                    {
                        foreach (var not in appUser.NotificationsRecieved)
                        {
                            Notification n = new Notification()
                            {
                                NotificationID = not.NotificationID,
                                Read           = not.Read,
                                Removed        = not.Removed
                            };

                            if (not.Notification != null)
                            {
                                n.Title            = not.Notification.NotificationTitle;
                                n.Message          = not.Notification.NotificationMessage;
                                n.PushDateTime     = not.Notification.PushDateTime;
                                n.ActionLink       = not.Notification.ActionLink;
                                n.NotificationType = (int)not.Notification.TypeOfNotification;
                                n.ResourceId       = not.Notification.ResourceId;
                            }
                            notificationsResponse.UserNotifications.Add(n);
                        }
                    }
                }

                response = this.Request.CreateResponse(HttpStatusCode.OK, notificationsResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
        public HttpResponseMessage Post([FromBody] WatchedLearningResourceRequest request)
        {
            HttpResponseMessage response;
            int appUserId;
            int learningResourceId;

            try
            {
                WatchedLearningResourceResponse followWatchedLearningResourceResponse = new WatchedLearningResourceResponse();

                appUserId          = Convert.ToInt32(request.AppUserId);
                learningResourceId = Convert.ToInt32(request.WatchedLearningResourceId);

                using (TechReady.Portal.Models.TechReadyDbContext ctx = new TechReady.Portal.Models.TechReadyDbContext())
                {
                    var appuser = (from c in ctx.AppUsers
                                   where c.AppUserID == appUserId
                                   select c).
                                  FirstOrDefault();

                    if (appuser != null)
                    {
                        var watchedLearningResource = (from c in ctx.LearningResources
                                                       where c.LearningResourceID == learningResourceId
                                                       select c).FirstOrDefault();


                        if (appuser.WatchedLearningResources == null)
                        {
                            appuser.WatchedLearningResources = new List <LearningResource>();
                        }
                        if (watchedLearningResource != null)
                        {
                            appuser.WatchedLearningResources.Add(watchedLearningResource);
                            ctx.SaveChanges();
                        }
                    }
                }

                response = this.Request.CreateResponse(HttpStatusCode.OK, followWatchedLearningResourceResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
        public HttpResponseMessage Post([FromBody] FeedbackRequest request)
        {
            HttpResponseMessage response;

            try
            {
                FeedbackResponse feedbackResponse = new FeedbackResponse();

                using (TechReady.Portal.Models.TechReadyDbContext ctx = new TechReady.Portal.Models.TechReadyDbContext())
                {
                    var appUserId = Convert.ToInt32(request.AppUserId);
                    var appuser   = (from c in ctx.AppUsers
                                     where c.AppUserID == appUserId select c).
                                    FirstOrDefault();

                    if (appuser != null)
                    {
                        AppFeedback feedback = new AppFeedback()
                        {
                            AppUserID    = appUserId,
                            Email        = request.Email,
                            FeedbackText = request.Feedback,
                            FeedbackType = request.FeedbackType,
                            Name         = request.Name
                        };

                        ctx.AppFeedbacks.Add(feedback);

                        ctx.SaveChanges();

                        feedbackResponse.ResponseText = "Thank you for sharing your feedback!";
                    }
                    else
                    {
                        feedbackResponse.ResponseText = "User is not registered, Please register to provide feedback";
                    }
                }

                response = this.Request.CreateResponse(HttpStatusCode.OK, feedbackResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
Example #6
0
        public HttpResponseMessage Post([FromBody] HomeRequest request)
        {
            HttpResponseMessage response;

            try
            {
                HomeResponse homeResponse = new HomeResponse();
                homeResponse.AllEvents = new ObservableCollection <TechReady.Common.Models.Event>();

                using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
                {
                    var events = (from c in ctx.Events
                                  where (c.EventStatus == DbModel.EventStatus.Tentative || c.EventStatus == DbModel.EventStatus.Confirmed) &&
                                  c.EventVisibility == DbModel.EventVisibility.Visible
                                  select c).ToList();


                    foreach (var ev in events)
                    {
                        try
                        {
                            if (ev.EventToDate.HasValue &&
                                (DateTime.Now.Date - ev.EventToDate.Value.Date).TotalDays > 1)
                            {
                                continue;
                            }

                            homeResponse.AllEvents.Add(CreateDxEvent(ev));
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.WriteLine(ex.Message);
                        }
                    }
                }

                response = this.Request.CreateResponse(HttpStatusCode.OK, homeResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
        public HttpResponseMessage Post([FromBody] LearningResourcesRequest request)
        {
            HttpResponseMessage response;

            try
            {
                LearningResourcesResponse learningResourcesResponse = new LearningResourcesResponse
                {
                    LearningResources = new ObservableCollection <LearningResource>()
                };


                using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
                {
                    var learningResources = (from c in ctx.LearningResources
                                             select c).ToList();

                    foreach (var lr in learningResources)
                    {
                        try
                        {
                            learningResourcesResponse.LearningResources.Add(CreateDxLearningResource(lr));
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.WriteLine(ex.Message);
                        }
                    }
                }

                response = Request.CreateResponse(HttpStatusCode.OK, learningResourcesResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
Example #8
0
        public HttpResponseMessage Post([FromBody] SpeakersRequest request)
        {
            HttpResponseMessage response;

            try
            {
                SpeakersResponse speakersResponse = new SpeakersResponse();
                speakersResponse.AllSpeakers = new ObservableCollection <TechReady.Common.Models.TrackSpeaker>();

                using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
                {
                    var speakers = (from c in ctx.Speakers
                                    select c).ToList();

                    foreach (var speaker in speakers)
                    {
                        try
                        {
                            speakersResponse.AllSpeakers.Add(CreateDxSpeaker(speaker));
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.WriteLine(ex.Message);
                        }
                    }
                }

                response = this.Request.CreateResponse(HttpStatusCode.OK, speakersResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
Example #9
0
        public HttpResponseMessage Post([FromBody] MarkNotificationRequest request)
        {
            HttpResponseMessage response;

            try
            {
                MarkNotificationResponse notificationsResponse = new MarkNotificationResponse();

                using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
                {
                    var appUserId      = Convert.ToInt32(request.AppUserId);
                    var notificationId = Convert.ToInt32(request.NotificationId);

                    var appUser = (from c in ctx.AppUserNotificationActions
                                   where c.AppUserID == appUserId && c.NotificationID == notificationId
                                   select c).FirstOrDefault();

                    if (appUser != null)
                    {
                        appUser.Read = true;
                    }
                    ctx.SaveChanges();
                }



                response = this.Request.CreateResponse(HttpStatusCode.OK, notificationsResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
Example #10
0
        public static TechnologiesResponse CreateTechnologiesResponse()
        {
            TechnologiesResponse techResponse = new TechnologiesResponse();

            techResponse.AudienceTypes         = new List <AudienceType>();
            techResponse.AudienceOrgTypes      = new List <AudienceOrg>();
            techResponse.SecondaryTechnologies = new List <SecondaryTechnology>();
            techResponse.Cities = new List <City>();


            using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
            {
                var audience = (from c in ctx.AudienceTypes
                                select c).ToList();

                foreach (var ev in audience)
                {
                    try
                    {
                        var at = new AudienceType()
                        {
                            AudienceTypeId   = ev.AudienceTypeID,
                            AudienceTypeName = ev.TypeOfAudience
                        };

                        techResponse.AudienceTypes.Add(at);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.Message);
                    }
                }

                var audienceOrg = (from c in ctx.AudienceOrgs select c).ToList();

                foreach (var at in audienceOrg)
                {
                    try
                    {
                        var ao = new AudienceOrg()
                        {
                            AudienceOrgId    = at.AudienceOrgID,
                            AudienceTypeName = at.AudienceType1.TypeOfAudience,
                            AudienceOrgName  = at.AudOrg
                        };

                        techResponse.AudienceOrgTypes.Add(ao);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.Message);
                    }
                }

                var stList = (from c in ctx.PrimaryTechnologies
                              select c).ToList();

                foreach (var st in stList)
                {
                    try
                    {
                        var dxSt = new SecondaryTechnology()
                        {
                            PrimaryTechnologyId     = st.PrimaryTechnologyID,
                            SecondaryTechnologyId   = st.PrimaryTechnologyID,
                            SecondaryTechnologyName = st.PrimaryTech,
                            PrimaryTechnologyName   = st.PrimaryTech
                        };

                        techResponse.SecondaryTechnologies.Add(dxSt);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.Message);
                    }
                }


                var cl = (from c in ctx.Cities
                          select c).ToList();

                foreach (var c in cl)
                {
                    try
                    {
                        var dxc = new City()
                        {
                            CityName = c.CityName,
                        };
                        if (c.Location != null)
                        {
                            dxc.Location = new GeoCodeItem()
                            {
                                Latitude  = c.Location.Latitude,
                                Longitude = c.Location.Longitude
                            };
                        }

                        techResponse.Cities.Add(dxc);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine(ex.Message);
                    }
                }
            }
            return(techResponse);
        }
        public HttpResponseMessage Post([FromBody] CheckProfileRequest request)
        {
            HttpResponseMessage response;

            try
            {
                var technologiesResponse = TechnologiesController.CreateTechnologiesResponse();

                CheckProfileResponse checkProfileResponse = new CheckProfileResponse()
                {
                    Cities                = technologiesResponse.Cities,
                    AudienceOrgTypes      = technologiesResponse.AudienceOrgTypes,
                    AudienceTypes         = technologiesResponse.AudienceTypes,
                    SecondaryTechnologies = technologiesResponse.SecondaryTechnologies,
                };

                using (DbModel.TechReadyDbContext ctx = new DbModel.TechReadyDbContext())
                {
                    var appUser = (from c in ctx.AppUsers
                                   where
                                   c.AuthProviderName == request.AuthProvider &&
                                   c.AuthProviderUserId == request.AuthProviderUserId
                                   select c).FirstOrDefault();

                    if (appUser != null)
                    {
                        checkProfileResponse.City = new City()
                        {
                            CityName = appUser.CityName,
                        };
                        if (appUser.City.Location != null)
                        {
                            checkProfileResponse.City.Location = new GeoCodeItem()
                            {
                                Latitude  = appUser.City.Location.Latitude,
                                Longitude = appUser.City.Location.Longitude
                            };
                        }

                        if (appUser.Location != null)
                        {
                            checkProfileResponse.Location = new GeoCodeItem()
                            {
                                Latitude  = appUser.Location.Latitude,
                                Longitude = appUser.Location.Longitude
                            };
                        }

                        checkProfileResponse.Town = appUser.Town;

                        checkProfileResponse.AuthProvider       = request.AuthProvider;
                        checkProfileResponse.AuthProviderUserId = request.AuthProviderUserId;
                        checkProfileResponse.Email                   = appUser.Email;
                        checkProfileResponse.FullName                = appUser.FullName;
                        checkProfileResponse.IsRegistered            = true;
                        checkProfileResponse.UserId                  = appUser.AppUserID.ToString();
                        checkProfileResponse.DeviceId                = appUser.DeviceId;
                        checkProfileResponse.SelectedAudienceOrgType = new AudienceOrg()
                        {
                            AudienceTypeName = appUser.AudienceOrg.AudienceType1.TypeOfAudience,
                            AudienceOrgId    = appUser.AudienceOrg.AudienceOrgID,
                            AudienceOrgName  = appUser.AudienceOrg.AudOrg
                        };
                        checkProfileResponse.SelectedAudienceType = new AudienceType()
                        {
                            AudienceTypeName = appUser.AudienceOrg.AudienceType1.TypeOfAudience,
                            AudienceTypeId   = appUser.AudienceOrg.AudienceType1.AudienceTypeID
                        };

                        foreach (var tech in appUser.TechnologyTags)
                        {
                            var PrimaryTech =
                                checkProfileResponse.SecondaryTechnologies.FirstOrDefault(
                                    x => x.PrimaryTechnologyId == tech.PrimaryTechnologyID);

                            if (PrimaryTech != null)
                            {
                                PrimaryTech.IsSelected = true;
                            }
                        }
                    }
                }
                response = this.Request.CreateResponse(HttpStatusCode.OK, checkProfileResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }
Example #12
0
        public async Task <HttpResponseMessage> Post([FromBody] ProfileRequest request)
        {
            HttpResponseMessage response;

            try
            {
                var profileResponse = new ProfileResponse();

                using (DbModel.TechReadyDbContext ctx = new   DbModel.TechReadyDbContext())
                {
                    var appUser = (from c in ctx.AppUsers
                                   where
                                   c.AuthProviderName == request.AuthProvider &&
                                   c.AuthProviderUserId == request.AuthProviderUserId
                                   select c).FirstOrDefault();

                    if (appUser == null)
                    {
                        appUser = new   DbModel.AppUser();
                        ctx.AppUsers.Add(appUser);
                        appUser.RegistrationDateTime = DateTime.Now;
                    }

                    appUser.CityName = request.City.CityName;
                    appUser.Town     = request.Town;
                    if (request.Location != null)
                    {
                        appUser.Location = ConvertGeoCode(request.Location);
                    }
                    appUser.AudienceOrgID      = request.SelectedAudienceOrgType.AudienceOrgId;
                    appUser.AuthProviderName   = request.AuthProvider;
                    appUser.AuthProviderUserId = request.AuthProviderUserId;
                    appUser.Email    = request.Email;
                    appUser.FullName = request.FullName;



                    if (appUser.TechnologyTags == null)
                    {
                        appUser.TechnologyTags = new List <DbModel.PrimaryTechnology>();
                    }

                    foreach (var tech in request.SecondaryTechnologies)
                    {
                        var c = (from t in ctx.PrimaryTechnologies
                                 where t.PrimaryTechnologyID == tech.PrimaryTechnologyId
                                 select t).FirstOrDefault();
                        if (c != null)
                        {
                            if (tech.IsSelected)
                            {
                                appUser.TechnologyTags.Add(c);
                            }
                            else
                            {
                                if (
                                    appUser.TechnologyTags.FirstOrDefault(
                                        x => x.PrimaryTechnologyID == c.PrimaryTechnologyID) != null)
                                {
                                    appUser.TechnologyTags.Remove(c);
                                }
                            }
                        }
                    }
                    ctx.SaveChanges();
                    if (request.PushEnabled && !string.IsNullOrEmpty(request.PushId))
                    {
                        //Create/Update if the Platform Changes or Notifications are Enabled
                        if ((appUser.DevicePlatform != request.DevicePlatform) ||
                            (appUser.PushEnabled != request.PushEnabled) ||
                            string.IsNullOrEmpty(appUser.DeviceId) ||
                            appUser.PushId != request.PushId
                            )
                        {
                            appUser.DeviceId = await hub.CreateRegistrationIdAsync();

                            RegistrationDescription registration = null;
                            switch (request.DevicePlatform)
                            {
                            case "mpns":
                                registration = new MpnsRegistrationDescription(request.PushId);
                                break;

                            case "wns":
                                registration = new WindowsRegistrationDescription(request.PushId);
                                break;

                            case "apns":
                                registration = new AppleRegistrationDescription(request.PushId);
                                break;

                            case "gcm":
                                registration = new GcmRegistrationDescription(request.PushId);
                                break;

                            default:
                                throw new HttpResponseException(HttpStatusCode.BadRequest);
                            }
                            registration.RegistrationId = appUser.DeviceId;

                            registration.Tags =
                                new HashSet <string>(appUser.TechnologyTags.Select(x => x.PrimaryTech).ToList().Select(x => x.Replace(" ", "_")).ToList());
                            registration.Tags.Add(request.SelectedAudienceType.AudienceTypeName.Replace(" ", "_"));
                            registration.Tags.Add("userId:" + appUser.AppUserID);

                            if (appUser.FollowedEvents != null)
                            {
                                foreach (var followedEvent in appUser.FollowedEvents)
                                {
                                    registration.Tags.Add("eventId:" + followedEvent.EventID.ToString());
                                }
                            }
                            if (appUser.FollowedSpeakers != null)
                            {
                                foreach (var followedSpeaker in appUser.FollowedSpeakers)
                                {
                                    registration.Tags.Add("speakerId:" + followedSpeaker.SpeakerID.ToString());
                                }
                            }


                            await hub.CreateOrUpdateRegistrationAsync(registration);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(appUser.DeviceId))
                        {
                            await hub.DeleteRegistrationAsync(appUser.DeviceId);

                            appUser.DeviceId = null;
                        }
                    }

                    appUser.DevicePlatform = request.DevicePlatform;
                    appUser.LastAccessTime = DateTime.Now;
                    appUser.PushEnabled    = request.PushEnabled;
                    appUser.PushId         = request.PushId;

                    ctx.SaveChanges();

                    profileResponse.UserId =
                        appUser.AppUserID;
                }
                response = this.Request.CreateResponse(HttpStatusCode.OK, profileResponse);
                response.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
            }
            catch (Exception ex)
            {
                HttpError myCustomError = new HttpError(ex.Message)
                {
                    { "IsSuccess", false }
                };
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, myCustomError));
            }
            return(response);
        }