Exemplo n.º 1
0
        public async Task SendCommentNotificationToAttendee(Attende attendee, int eventID, string title, string message, int sentBy)
        {
            var           distinctDeviceTokenSessions = attendee.BookMarks.SelectMany(x => x.Attende.UserSessions).Where(x => x.IsActive == true && x.Platform != "Web" && !string.IsNullOrEmpty(x.DeviceToken)).Distinct(new UserDeviceTokenComparer()).ToList();
            Notifications notifications  = new Notifications();
            var           notificationID = await notifications.MaintainNotificationHistory(eventID, title, message, sentBy);

            EventLogic eventLogic = new EventLogic();
            await eventLogic.SendNotificationForSessions(distinctDeviceTokenSessions, title, message, eventID, sentBy, notificationID);
        }
Exemplo n.º 2
0
        public async Task sendAttendeeChatNotifications(int receiverID, string message, int eventID, string from, string channelID)
        {
            EventLogic       eventLogic = new EventLogic();
            var              sessions   = eventLogic.GetAttendeeSessions(receiverID);
            var              subject    = $"{from}";
            var              body       = message;
            NotificationData notificationData;

            foreach (var session in sessions)
            {
                notificationData = new NotificationData()
                {
                    ChannelId = channelID, IsChat = true, Token = session.AuthToken
                };
                eventLogic.SendNotificationFromFirebaseCloud(session.DeviceToken, subject, body);
                // await eventLogic.SendNotificationAndLogInDB(session.DeviceToken, subject, body, eventID, session.AttendesID.Value, 0);
            }
        }
Exemplo n.º 3
0
        public async Task <GPSAPILogin1> AttendiLogin(string email, string password, enPlatformTypes platform, string deviceToken, string isactive, Func <string, string> imageConvertionHandler, string imageSavePath, string mobileOSVersion, string mobileDeviceUniqueToken)
        {
            try
            {
                var           client        = new RestClient(string.Format("{0}/eventapp/api/Login", GalacticConfigs.GalacticApiBaseUrl));
                var           request       = new RestRequest(Method.POST);
                List <Event>  AccessList    = new List <Event>();
                GPSAPILogin1  accessEvents  = new GPSAPILogin1();
                AttendesLogic attendesLogic = new AttendesLogic();
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("content-type", "application/json");
                request.AddParameter("application/json", string.Format("{{\n\tEmail:'{0}',\n\tPassword:'******',\n\tToken:'{2}'\n}}", email, password, GalacticApiSecretKeyEncoded), ParameterType.RequestBody);
                IRestResponse <GPSAPILogin> response2 = client.Execute <GPSAPILogin>(request);
                EventLogic eventLogic = new EventLogic();
                Attende    attende;

                if (response2.Data == null)
                {
                    throw response2.ErrorException;
                }
                bool isAdmin = await IsAdmin(email, password);

                if (response2.Data.IsAuthenticated || isAdmin)
                {
                    LogoutExistingUsersWithSameFBToken(deviceToken);
                    attende = await Db.Attendes.FirstOrDefaultAsync(x => x.Email == email);

                    string authToken; // Guid.NewGuid().ToString("n");
                    response2.Data.Message         = null;
                    response2.Data.IsAuthenticated = true;
                    response2.Data.HasPassword     = true;
                    if (attende == null)
                    {
                        attende = new Attende
                        {
                            Email     = email,
                            Thumbnail = attendesLogic.GenerateImageFromName(response2.Data.FirstName, response2.Data.LastName, imageSavePath),
                            AddedON   = DateTime.Now,
                            FirstName = response2.Data.FirstName,
                            Lastname  = response2.Data.LastName,
                            IsSpeaker = response2.Data.AttendeeType?.ToLower() == "speaker"
                        };
                        Db.Attendes.Add(attende);
                        Db.SaveChanges();
                        authToken            = Authenticate.GenerateToken(attende.ID);
                        response2.Data.Token = authToken;
                        attende.UserSessions.Add(new UserSession
                        {
                            AuthToken   = authToken,
                            IsActive    = (isactive == "0" ? false : true),
                            Platform    = platform.ToString(),
                            CreateDate  = DateTime.Now,
                            DeviceToken = deviceToken
                        });
                        Db.SaveChanges();
                        foreach (var item in response2.Data.UserEvents)
                        {
                            if (Db.Events.Any(x => x.GalacticEventId == item.GalacticEventID))
                            {
                                var eventRecord = Db.Events.FirstOrDefault(x => x.GalacticEventId == item.GalacticEventID);
                                if (!Db.AttendesEvents.Any(x => x.AttendesID == attende.ID && x.EventID == eventRecord.ID))
                                {
                                    Db.AttendesEvents.Add(new AttendesEvent
                                    {
                                        AttendesID = attende.ID,
                                        EventID    = eventRecord.ID,
                                    });
                                }
                            }
                            else
                            {
                                //create event if not exsit
                                //add event activities
                                var eventActivities = EventActivities(item.GalacticEventID);
                                var @event          = new Event
                                {
                                    GalacticEventId = item.GalacticEventID,
                                    EventName       = item.EventName,
                                    AttendesEvents  = new List <AttendesEvent> {
                                        new AttendesEvent {
                                            AttendesID = attende.ID
                                        }
                                    },
                                    Activites = eventActivities.ProgramActivities.Select(x => new Activite
                                    {
                                        StartTime   = x.ActivityStartTime.ToSafeDate(),
                                        EndTime     = x.ActivityEndTime.ToSafeDate(),
                                        CreateON    = DateTime.Now,
                                        Description = x.ActivityName,
                                    }).ToList()
                                };
                                await eventLogic.AddUpdateEvent(@event);
                            }
                        }
                        await Db.SaveChangesAsync();
                    }
                    else
                    {
                        authToken            = Authenticate.GenerateToken(attende.ID);
                        response2.Data.Token = authToken;
                        foreach (var item in response2.Data.UserEvents)
                        {
                            if (Db.Events.Any(x => x.GalacticEventId == item.GalacticEventID))
                            {
                                if (!Db.AttendesEvents.Any(x => x.AttendesID == attende.ID))
                                {
                                    Db.AttendesEvents.Add(new AttendesEvent
                                    {
                                        AttendesID = attende.ID,
                                        EventID    = Db.Events.FirstOrDefault(x => x.GalacticEventId == item.GalacticEventID).ID,
                                    });
                                }
                            }
                            else
                            {
                                //create event if not exsit
                                var @event = new Event
                                {
                                    GalacticEventId = item.GalacticEventID,
                                    EventName       = item.EventName,
                                    AttendesEvents  = new List <AttendesEvent> {
                                        new AttendesEvent {
                                            AttendesID = attende.ID
                                        }
                                    }
                                };
                                await eventLogic.AddUpdateEvent(@event);
                            }
                        }
                        attende.UserSessions.Add(new UserSession
                        {
                            AuthToken               = authToken,
                            IsActive                = (isactive == "0" ? false : true),
                            Platform                = platform.ToString(),
                            CreateDate              = DateTime.Now,
                            DeviceToken             = deviceToken,
                            MobileOSVersion         = mobileOSVersion,
                            MobileDeviceUniqueToken = mobileDeviceUniqueToken
                        });
                        await Db.SaveChangesAsync();
                    }


                    //if (!isAdmin)
                    //{
                    //    foreach (var item in response2.Data.UserEvents)
                    //    {
                    //        var detailing = Db.Events.Where(x => x.GalacticEventId == item.GalacticEventID).FirstOrDefault();
                    //        if (detailing != null)
                    //        {
                    //            AccessList.Add(detailing);
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    AccessList = Db.AttendesEvents.Where(x => x.AttendesID == attende.ID).Select(x => x.Event).ToList();
                    //}

                    accessEvents.Token = response2.Data.Token;
                    accessEvents.Email = response2.Data.Email;

                    accessEvents.IsAuthenticated = response2.Data.IsAuthenticated;
                    accessEvents.Message         = response2.Data.Message;
                    accessEvents.HasPassword     = response2.Data.HasPassword;
                    accessEvents.IsValid         = response2.Data.IsValid;
                    accessEvents.UserID          = attende.ID;
                    accessEvents.UserFullName    = $"{attende.FirstName} {attende.Lastname}";
                    accessEvents.isAdmin         = attende.IsAdmin;
                    accessEvents.UserIcon        = imageConvertionHandler(attende.Thumbnail);
                    accessEvents.UserEvents      = CreateLoginEventDataEntity(AccessList, imageConvertionHandler, email).ToList();

                    return(accessEvents);
                }
                else
                {
                    //if(attende == null)
                    //{
                    //    throw new System.Web.HttpException((int)HttpStatusCode.Unauthorized, "Not Authorized");
                    //}
                    //response2.Data.UserEvents = new List<APIUserEvents>();
                }
                foreach (var item in response2.Data.UserEvents)
                {
                    var detailing = Db.Events.Where(x => x.GalacticEventId == item.GalacticEventID).FirstOrDefault();
                    if (detailing != null)
                    {
                        AccessList.Add(detailing);
                    }
                }

                accessEvents.Token           = response2.Data.Token;
                accessEvents.Email           = response2.Data.Email;
                accessEvents.IsAuthenticated = response2.Data.IsAuthenticated;
                accessEvents.Message         = response2.Data.Message;
                accessEvents.Password        = password;
                accessEvents.HasPassword     = response2.Data.HasPassword;
                accessEvents.IsValid         = response2.Data.IsValid;
                accessEvents.UserEvents      = CreateLoginEventDataEntity(AccessList, imageConvertionHandler, email).ToList();

                return(accessEvents);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }