public async Task <Response <Notification> > PutNotification(int userID, bool Messages, bool Notices, bool Report) { NotificationsController notificationController = new NotificationsController(); Response <Notification> responceNotification = new Response <Notification>(); Notification notification = new Notification(); responceNotification = await notificationController.GetNotificationbyUserID(userID); notification.Messages = Messages; notification.Notices = Notices; notification.Report = Report; if (!ModelState.IsValid) { responceNotification.status = "Failed"; responceNotification.model = null; return(responceNotification); } if (userID != notification.userID) { responceNotification.status = "Failed: Id did not match"; responceNotification.model = null; return(responceNotification); } db.Entry(notification).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!useridNotificationExists(userID)) { responceNotification.status = "Failed: Id did not Exist"; responceNotification.model = null; return(responceNotification); } else { throw; } } responceNotification.status = "Failed: Id did not match"; responceNotification.model = notification; return(responceNotification); }
public async Task <Response <Announcement> > PutAnnouncement(int id, Announcement announcement) { Response <Announcement> responseAnnouncement = new Response <Announcement>(); if (!ModelState.IsValid) { responseAnnouncement.status = "Failure"; responseAnnouncement.model = null; return(responseAnnouncement); } if (id != announcement.id) { responseAnnouncement.status = "Failed: ID did not match"; responseAnnouncement.model = null; return(responseAnnouncement); } var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var docfiles = new List <string>(); foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; if (postedFile.ContentLength == 0) { Response <Announcement> responseGetAnnouncement = new Response <Announcement>(); AnnouncementsController announcementController = new AnnouncementsController(); responseGetAnnouncement = await announcementController.GetAnnouncement(announcement.id); announcement.image = responseGetAnnouncement.model.image; } else { imageForBlob imageForBlob = new imageForBlob(); string blobImageURL = imageForBlob.ConvertfileForBlob(); announcement.image = blobImageURL; } } } db.Entry(announcement).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnnouncementExists(id)) { responseAnnouncement.status = "Failed: ID does not exist"; responseAnnouncement.model = null; return(responseAnnouncement); } else { throw; } } responseAnnouncement.status = "Success"; responseAnnouncement.model = announcement; List <Member> member = new List <Member>(); member = db.Members.Where(m => m.communityID == announcement.communityID).Include(x => x.user).ToList(); Community community = new Community(); community = await db.Communities.Where(m => m.communityID == announcement.communityID).FirstOrDefaultAsync(); string communityName = community.name; foreach (var item in member) { Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(item.userId); if (responceNotification.model != null) { if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Notices == true) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; // iOS var alert = "{\"aps\":{\"alert\":\"" + communityName + " : The Notice has been updated.\",\"id\":\"5\",\"communityid\":\"" + item.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(item.userId)); // Android //var notif = "{ \"data\" : {\"message\":\"You have a new Notice.\",\"id\":\"2\"}}"; var notif = "{\"data\":{\"message\":\"" + communityName + " : The Notice has been updated.\",\"badge\":\"1\",\"id\":\"5\",\"communityid\":\"" + item.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(item.userId)); } } } //else //{ // responseAnnouncement.status =Convert.ToString(item.userId); // responseAnnouncement.model = null; // return responseAnnouncement; //} } return(responseAnnouncement); }
public async Task <Response <Announcement> > PostAnnouncement(Announcement announcement) { try { Response <Announcement> responseAnnouncement = new Response <Announcement>(); if (!ModelState.IsValid) { responseAnnouncement.status = "Failure"; responseAnnouncement.model = null; return(responseAnnouncement); } if (announcement.image != null) { imageForBlob imageForBlob = new imageForBlob(); string blobImageURL = imageForBlob.ConvertfileForBlob(); announcement.image = blobImageURL; } 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); announcement.date = malayDateTime; db.Announcements.Add(announcement); await db.SaveChangesAsync(); responseAnnouncement.status = "Success"; responseAnnouncement.model = announcement; List <Member> member = new List <Member>(); member = db.Members.Where(m => m.communityID == announcement.communityID).Include(x => x.user).ToList(); Community community = new Community(); community = await db.Communities.Where(m => m.communityID == announcement.communityID).FirstOrDefaultAsync(); string communityName = community.name; foreach (var item in member) { Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(item.userId); if (responceNotification.model != null) { if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Notices == true) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; // iOS var alert = "{\"aps\":{\"alert\":\"" + communityName + " : You have a new Notice.\",\"id\":\"2\",\"communityid\":\"" + item.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(item.userId)); // Android //var notif = "{ \"data\" : {\"message\":\"You have a new Notice.\",\"id\":\"2\"}}"; var notif = "{\"data\":{\"message\":\"" + communityName + " : You have a new Notice.\",\"badge\":\"1\",\"id\":\"2\",\"communityid\":\"" + item.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(item.userId)); } } } //else //{ // responseAnnouncement.status =Convert.ToString(item.userId); // responseAnnouncement.model = null; // return responseAnnouncement; //} } return(responseAnnouncement); } catch (Exception ex) { throw ex; } }
public async Task <Response <Complaint> > PutComplaint(int id, Complaint complaint) { Response <Complaint> responseComplaint = new Response <Complaint>(); if (!ModelState.IsValid) { responseComplaint.status = "No Complaints"; responseComplaint.model = null; return(responseComplaint); } if (id != complaint.complaintID) { responseComplaint.status = "Failed: ID Did Not Match"; responseComplaint.model = null; return(responseComplaint); } db.Entry(complaint).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ComplaintExists(id)) { responseComplaint.status = "Failed: No Complaint ID Found"; responseComplaint.model = null; return(responseComplaint); } else { throw; } } responseComplaint.status = "Success"; responseComplaint.model = complaint; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(complaint.userID); int communityID = complaint.communityID; int complaintID = complaint.complaintID; var ComplaintFromDB = await(from l in db.Complaints where l.communityID == communityID && l.complaintID == complaintID select l).Include(x => x.community).FirstOrDefaultAsync(); if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Report == true) { // iOS var alert = "{\"aps\":{\"alert\":\"" + ComplaintFromDB.community.name + " : Your iReport has been Received.\",\"id\":\"3\",\"communityid\":\"" + complaint.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(complaint.userID)); // Android //"{ \"data\" : {\"message\":\"Your iReport has been Received.\",\"id\":\"3\"}}" var notif = "{\"data\":{\"message\":\"" + ComplaintFromDB.community.name + " : Your iReport has been Received.\",\"badge\":\"1\",\"id\":\"3\",\"communityid\":\"" + complaint.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(complaint.userID)); } } return(responseComplaint); }
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); } }
public async Task <Response <Chat> > PostChatForAdmin(string description, int userIdTo, int userIdFrom, int communityID, string image) { Chat chat = new Chat(); chat.desc = description; chat.to = userIdTo; chat.from = userIdFrom; chat.isRead = false; 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); chat.Date = malayDateTime; chat.communityID = communityID; chat.image = image; Response <Chat> chatResponse = new Response <Chat>(); chatResponse.model = chat; if (!ModelState.IsValid) { chatResponse.status = "Failure"; chatResponse.model = null; return(chatResponse); } db.Chats.Add(chat); await db.SaveChangesAsync(); chatResponse.status = "Success"; chatResponse.model = chat; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(userIdTo); var ChatFromDB = await(from l in db.Chats where l.communityID == communityID select l).Include(x => x.community).FirstOrDefaultAsync(); if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Messages == true) { // iOS var alert = "{\"aps\":{\"alert\":\"" + ChatFromDB.community.name + " : You have a new message.\",\"id\":\"1\",\"communityid\":\"" + chat.communityID + "\",\"Message\":\"" + chat.desc + "\",\"image\":\"" + chat.image + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(userIdTo)); // Android //"{ \"data\" : {\"message\":\"You have a new message.\",\"id\":\"1\"}}" var notif = "{\"data\":{\"message\":\"" + ChatFromDB.community.name + " : You have a new message.\",\"badge\":\"1\",\"id\":\"1\",\"Message\":\"" + chat.desc + "\",\"image\":\"" + chat.image + "\",\"communityid\":\"" + chat.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(userIdTo)); } } return(chatResponse); //var alert = "{\"aps\":{\"alert\":\"You have a new message.\",\"badge\":" + msgCount + ",\"id\":\"2\",\"sound\":\"default\"}}"; //var outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, messages.messageTo); //var notif = "{ \"data\" : {\"message\":\"You have a new message.\",\"badge\":" + msgCount + ",\"id\":\"2\"}}"; //outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, messages.messageTo); }