Esempio n. 1
0
        public async Task <Response <MobSettingDTOAndroid> > PutUserData(MobSettingDTOAndroid mobSettingDTOAndroid, int dummy)
        {
            try
            {
                UsersController userController = new UsersController();
                Response <User> userResponse   = new Response <User>();
                Response <MobSettingDTOAndroid> MobSettingDTOAndroidResponse = new Response <MobSettingDTOAndroid>();

                MembersController memberController = new MembersController();


                userResponse = userController.GetCommunityUserbyID(mobSettingDTOAndroid.userID, 1);
                if (userResponse.model == null)
                {
                    MobSettingDTOAndroidResponse.status = "Failed: No User Found";
                    MobSettingDTOAndroidResponse.model  = null;
                    return(MobSettingDTOAndroidResponse);
                }
                User user = new User();
                user = userResponse.model;
                if (mobSettingDTOAndroid.EmailID != null)
                {
                    user.emailID = mobSettingDTOAndroid.EmailID;
                }
                if (mobSettingDTOAndroid.password != null)
                {
                    user.password = mobSettingDTOAndroid.password;
                }
                if (mobSettingDTOAndroid.emergencyContactName1 != null)
                {
                    user.emergencyContactName1 = mobSettingDTOAndroid.emergencyContactName1;
                }
                if (mobSettingDTOAndroid.emergencyContactName2 != null)
                {
                    user.emergencyContactName2 = mobSettingDTOAndroid.emergencyContactName2;
                }
                if (mobSettingDTOAndroid.emergencyContactNumber1 != null)
                {
                    user.emergencyContactNumber1 = mobSettingDTOAndroid.emergencyContactNumber1;
                }

                if (mobSettingDTOAndroid.emergencyContactNumber2 != null)
                {
                    user.emergencyContactNumber2 = mobSettingDTOAndroid.emergencyContactNumber2;
                }
                if (mobSettingDTOAndroid.language != null)
                {
                    user.language = mobSettingDTOAndroid.language;
                }

                db.Entry(user).State = EntityState.Modified;
                await db.SaveChangesAsync();

                if (mobSettingDTOAndroid.communityList != null)
                {
                    foreach (var item in mobSettingDTOAndroid.communityList)
                    {
                        Response <Member> memberResponse = new Response <Member>();
                        memberResponse = await memberController.GetCommunityMember(item.communityID, mobSettingDTOAndroid.userID);

                        Member member = new Member();
                        member = memberResponse.model;
                        if (item.address != null)
                        {
                            member.address = item.address;
                        }
                        if (item.streetFloor != null)
                        {
                            member.streetFloor = item.streetFloor;
                        }

                        db.Entry(member).State = EntityState.Modified;
                        await db.SaveChangesAsync();
                    }
                }
                Response <Notification> responceNotification   = new Response <Notification>();
                NotificationsController notificationController = new NotificationsController();
                responceNotification = await notificationController.GetNotificationbyUserID(mobSettingDTOAndroid.userID);

                Notification notification = new Notification();
                notification = responceNotification.model;
                if (mobSettingDTOAndroid.Messages == null)
                {
                    notification.Messages = notification.Messages;
                }
                if (mobSettingDTOAndroid.Messages == "true")
                {
                    notification.Messages = true;
                }
                if (mobSettingDTOAndroid.Messages == "false")
                {
                    notification.Messages = false;
                }



                if (mobSettingDTOAndroid.Notices == null)
                {
                    notification.Notices = notification.Notices;
                }
                if (mobSettingDTOAndroid.Notices == "true")
                {
                    notification.Notices = true;
                }
                if (mobSettingDTOAndroid.Notices == "false")
                {
                    notification.Notices = false;
                }


                if (mobSettingDTOAndroid.Report == null)
                {
                    notification.Report = notification.Report;
                }
                if (mobSettingDTOAndroid.Report == "true")
                {
                    notification.Report = true;
                }
                if (mobSettingDTOAndroid.Report == "false")
                {
                    notification.Report = false;
                }

                responceNotification = await notificationController.PutNotification(mobSettingDTOAndroid.userID, notification);

                responceNotification.model          = notification;
                MobSettingDTOAndroidResponse.status = "Success";
                MobSettingDTOAndroidResponse.model  = mobSettingDTOAndroid;
                return(MobSettingDTOAndroidResponse);
            }
            catch (Exception ex)
            {
                Response <MobSettingDTOAndroid> MobSettingDTOAndroidResponse = new Response <MobSettingDTOAndroid>();
                MobSettingDTOAndroidResponse.status = ex.Message;
                MobSettingDTOAndroidResponse.model  = null;
                return(MobSettingDTOAndroidResponse);
            }
        }
Esempio n. 2
0
        public async Task <Response <Alert> > PostAlert(int communityID, int UserID, string number1, string number2, string number3)
        {
            number1 = number1.Trim();
            number2 = number2.Trim();
            number3 = number3.Trim();
            Alert            alert         = new Alert();
            Response <Alert> responceAlert = new Response <Alert>();

            if (!ModelState.IsValid)
            {
                responceAlert.status = "Failuer";
                responceAlert.model  = null;
                return(responceAlert);
            }
            alert.communityID = communityID;
            alert.userID      = UserID;



            DateTime ServerDateTime = DateTime.Now;
            DateTime utcDateTime    = ServerDateTime.ToUniversalTime();

            // ID from:
            // "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone"
            // See http://msdn.microsoft.com/en-us/library/system.timezoneinfo.id.aspx
            string       malayTimeZoneKey = "Singapore Standard Time";
            TimeZoneInfo malayTimeZone    = TimeZoneInfo.FindSystemTimeZoneById(malayTimeZoneKey);
            DateTime     malayDateTime    = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, malayTimeZone);


            alert.date     = malayDateTime;
            alert.isViewed = false;
            MembersController memberController = new MembersController();
            Response <Member> responceMember   = new Response <Member>();

            responceMember = await memberController.GetCommunityMember(communityID, UserID);

            if (responceMember == null)
            {
                responceAlert.status = "Failuer: responceMember not found";
                responceAlert.model  = null;
                return(responceAlert);
            }
            alert.memberID = responceMember.model.id;



            db.Alerts.Add(alert);
            await db.SaveChangesAsync();

            List <CommunityEmergencyContacts> CommunityContactsList = new List <CommunityEmergencyContacts>();

            CommunityContactsList = (from l in db.CommunityEmergencyContacts
                                     where l.communityID == communityID
                                     select l).ToList();

            UsersController userController = new UsersController();
            Response <User> userResponse   = new Response <User>();

            userResponse = userController.GetCommunityUserbyID(UserID, 1);
            //if (userResponse == null)
            //{
            //    responceAlert.status = "Failuer: userResponse not found";
            //    responceAlert.model = null;
            //    return responceAlert;
            //}
            //if (userResponse.model == null)
            //{
            //    responceAlert.status = "Failuer: userResponse.model not found";
            //    responceAlert.model = null;
            //    return responceAlert;
            //}
            using (var wb = new WebClient())
            {
                if (number1 != "no")
                {
                    bool plusCheck = number1.Contains("+");
                    if (plusCheck == true)
                    {
                        string[] contactArrayPlus = number1.Split('+');
                        number1 = contactArrayPlus[1];
                        bool isNumeric = number1.All(char.IsDigit);
                        if (isNumeric == true)
                        {
                            var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + number1 + "&senderid=onewaysms&languagetype=1&message= SECURITY ALERT TRIGGERED! %0A NAME : " + userResponse.model.firstName + " " + userResponse.model.lastName + " %0A ADDRESS : " + responceMember.model.address + " " + responceMember.model.streetFloor + " %0A Contact : " + userResponse.model.contact + "");
                            //var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + userResponse.model.emergencyContactNumber1 + "&senderid=onewaysms&languagetype=1&message=This Alert Notification is sent by " + userResponse.model.firstName + "");
                        }
                    }
                    else
                    {
                        char[] num1 = number1.Take(2).ToArray();
                        if (num1[0] != '0' && num1[1] != '0')
                        {
                            number1 = "00" + number1;
                        }
                        int    lenth            = number1.Length;
                        string contactArrayPlus = number1.Substring(2);
                        number1 = contactArrayPlus;
                        bool isNumeric = number1.All(char.IsDigit);
                        if (isNumeric == true)
                        {
                            var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + number1 + "&senderid=onewaysms&languagetype=1&message= SECURITY ALERT TRIGGERED! %0A NAME : " + userResponse.model.firstName + " " + userResponse.model.lastName + " %0A ADDRESS : " + responceMember.model.address + " " + responceMember.model.streetFloor + " %0A Contact : " + userResponse.model.contact + "");
                            //var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + userResponse.model.emergencyContactNumber1 + "&senderid=onewaysms&languagetype=1&message=This Alert Notification is sent by " + userResponse.model.firstName + "");
                        }
                    }
                }



                if (number2 != "no")
                {
                    bool plusCheck = number2.Contains("+");
                    if (plusCheck == true)
                    {
                        string[] contactArrayPlus = number2.Split('+');
                        number2 = contactArrayPlus[1];
                        bool isNumeric = number2.All(char.IsDigit);
                        if (isNumeric == true)
                        {
                            var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + number2 + "&senderid=onewaysms&languagetype=1&message= SECURITY ALERT TRIGGERED! %0A NAME : " + userResponse.model.firstName + " " + userResponse.model.lastName + " %0A ADDRESS : " + responceMember.model.address + " " + responceMember.model.streetFloor + " %0A Contact : " + userResponse.model.contact + "");
                            //var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + userResponse.model.emergencyContactnumber2 + "&senderid=onewaysms&languagetype=1&message=This Alert Notification is sent by " + userResponse.model.firstName + "");
                        }
                    }
                    else
                    {
                        char[] num2 = number2.Take(2).ToArray();
                        if (num2[0] != '0' && num2[1] != '0')
                        {
                            number2 = "00" + number2;
                        }
                        int    lenth            = number2.Length;
                        string contactArrayPlus = number2.Substring(2);
                        number2 = contactArrayPlus;
                        bool isNumeric = number2.All(char.IsDigit);
                        if (isNumeric == true)
                        {
                            var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + number2 + "&senderid=onewaysms&languagetype=1&message= SECURITY ALERT TRIGGERED! %0A NAME : " + userResponse.model.firstName + " " + userResponse.model.lastName + " %0A ADDRESS : " + responceMember.model.address + " " + responceMember.model.streetFloor + " %0A Contact : " + userResponse.model.contact + "");
                            //var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + userResponse.model.emergencyContactnumber2 + "&senderid=onewaysms&languagetype=1&message=This Alert Notification is sent by " + userResponse.model.firstName + "");
                        }
                    }
                }
                if (number3 != "no")
                {
                    bool plusCheck = number3.Contains("+");
                    if (plusCheck == true)
                    {
                        string[] contactArrayPlus = number3.Split('+');
                        number3 = contactArrayPlus[1];
                        bool isNumeric = number3.All(char.IsDigit);
                        if (isNumeric == true)
                        {
                            var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + number3 + "&senderid=onewaysms&languagetype=1&message= SECURITY ALERT TRIGGERED! %0A NAME : " + userResponse.model.firstName + " " + userResponse.model.lastName + " %0A ADDRESS : " + responceMember.model.address + " " + responceMember.model.streetFloor + " %0A Contact : " + userResponse.model.contact + "");
                            //var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + userResponse.model.emergencyContactnumber3 + "&senderid=onewaysms&languagetype=1&message=This Alert Notification is sent by " + userResponse.model.firstName + "");
                        }
                    }
                    else
                    {
                        char[] num3 = number3.Take(2).ToArray();
                        if (num3[0] != '0' && num3[1] != '0')
                        {
                            number3 = "00" + number3;
                        }
                        int    lenth            = number3.Length;
                        string contactArrayPlus = number3.Substring(2);
                        number3 = contactArrayPlus;
                        bool isNumeric = number3.All(char.IsDigit);
                        if (isNumeric == true)
                        {
                            var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + number3 + "&senderid=onewaysms&languagetype=1&message= SECURITY ALERT TRIGGERED! %0A NAME : " + userResponse.model.firstName + " " + userResponse.model.lastName + " %0A ADDRESS : " + responceMember.model.address + " " + responceMember.model.streetFloor + " %0A Contact : " + userResponse.model.contact + "");
                            //var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=" + userResponse.model.emergencyContactnumber3 + "&senderid=onewaysms&languagetype=1&message=This Alert Notification is sent by " + userResponse.model.firstName + "");
                        }
                    }
                }
            }

            //using (var wb = new WebClient())
            //{
            //    var response = wb.DownloadString("http://gateway.onewaysms.com.my:10001/api.aspx?apiusername=API112A4611M6&apipassword=API112A4611M6EP9PC&mobileno=60126658836,923315254672,923125199654,923105224222&senderid=onewaysms&languagetype=1&message=Testing SMS API Hi Vineet");
            //}
            responceAlert.status = "Success";
            responceAlert.model  = alert;
            return(responceAlert);
        }