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 <User> > PostCommunityAdminUser(string name, string password) { User user = new User(); user.password = password; user.firstName = name; Response <User> userResponse = new Response <User>(); if (!ModelState.IsValid) { userResponse.status = "Failure"; userResponse.model = null; return(userResponse); } //if (UserExists(user.emailID)) //{ // userResponse.status = "Failed: Already Exist"; // var existUser = await (from l in db.Users // where l.emailID == user.emailID // select l).FirstOrDefaultAsync(); // userResponse.model = existUser; // return userResponse; //} db.Users.Add(user); await db.SaveChangesAsync(); var userFromDB = await(from u in db.Users where u.firstName == name && u.password == password select u).FirstOrDefaultAsync(); Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); Notification notification = new Notification(); notification.Messages = false; notification.Notices = false; notification.Report = false; notification.userID = userFromDB.userID; responceNotification = await notificationController.PostNotification(notification); await db.SaveChangesAsync(); userResponse.status = "Success"; userResponse.model = user; return(userResponse); }
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 <IHttpActionResult> PostUser() { var httpRequest = HttpContext.Current.Request; string root = HttpContext.Current.Server.MapPath("~/App_Data"); var provider = new MultipartFormDataStreamProvider(root); if (Request.Content.IsMimeMultipartContent()) { await Request.Content.ReadAsMultipartAsync(provider); User user = new User(); Member member = new Member(); foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { if (key.Equals("emailID")) { user.emailID = val; //var userEmail = db.Users.Where(x => x.emailID == val).FirstOrDefault(); //if (userEmail == null) //{ // user.emailID = val; //} //else //{ // Response<User> userResponse = new Response<User>(); // userResponse.status = "Failed: This Email Id Already Exists."; // userResponse.model = null; // return Ok(userResponse); //} } if (key.Equals("password")) { user.password = val; } if (key.Equals("firstName")) { user.firstName = val; } if (key.Equals("lastName")) { user.lastName = val; } if (key.Equals("country")) { user.country = val; } if (key.Equals("gender")) { user.gender = val; } if (key.Equals("contact")) { user.contact = val; } if (key.Equals("emergencyContactName1")) { user.emergencyContactName1 = val; } if (key.Equals("emergencyContactNumber1")) { user.emergencyContactNumber1 = val; } if (key.Equals("emergencyContactName2")) { user.emergencyContactName2 = val; } if (key.Equals("emergencyContactNumber2")) { user.emergencyContactNumber2 = val; } if (key.Equals("address")) { member.address = val; } if (key.Equals("streetFloor")) { member.streetFloor = val; } if (key.Equals("communityID")) { member.communityID = Convert.ToInt32(val); } if (key.Equals("lat")) { user.lat = Convert.ToDouble(val); } if (key.Equals("lng")) { user.lng = Convert.ToDouble(val); } if (key.Equals("language")) { user.language = val; } if (key.Equals("userType")) { user.userType = val; } } } user.Islogout = false; user.isMainAdmin = false; member.isBlocked = false; member.isAlertBlocked = false; Response <UserMemberDTO> userMemberResponse = new Response <UserMemberDTO>(); UserMemberDTO userMemberDto = new UserMemberDTO(); if (!ModelState.IsValid) { userMemberResponse.status = "Failure"; userMemberResponse.model = userMemberDto; return(Ok(userMemberResponse)); } if (UserExists(user.emailID)) { userMemberResponse.status = "Failed: User Already Exist"; userMemberDto.user = await(from l in db.Users where l.emailID == user.emailID select l).FirstOrDefaultAsync(); userMemberResponse.model = userMemberDto; return(Ok(userMemberResponse)); } imageForBlob imageForBlob = new imageForBlob(); string blobImageURL = imageForBlob.ConvertImageForBlob(); user.image = blobImageURL; db.Users.Add(user); await db.SaveChangesAsync(); AccountController accountController = new AccountController(); RegisterBindingModel registerBindingModel = new RegisterBindingModel(); registerBindingModel.Email = user.emailID; registerBindingModel.Password = user.password; registerBindingModel.ConfirmPassword = user.password; using (var client = new HttpClient()) { var values = new Dictionary <string, string> { { "Email", user.emailID }, { "Password", user.password }, { "ConfirmPassword", user.password } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync(accountRegisterUri, content); var responseString = await response.Content.ReadAsStringAsync(); } MembersController memberController = new MembersController(); Response <Member> responseMember = new Response <Member>(); userMemberDto.user = await(from l in db.Users where l.emailID == user.emailID select l).FirstOrDefaultAsync(); member.userId = userMemberDto.user.userID; responseMember = await memberController.PostMember(member); responseMember = await memberController.GetMember(responseMember.model.id); Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); Notification notification = new Notification(); notification.Messages = true; notification.Notices = true; notification.Report = true; notification.userID = userMemberDto.user.userID; responceNotification = await notificationController.PostNotification(notification); userMemberResponse.status = "Success"; userMemberDto.member = member; userMemberDto.user = user; userMemberDto.AdminID = responseMember.model.community.adminUserID; userMemberResponse.model = userMemberDto; return(Ok(userMemberResponse)); } else { Response <User> userResponse = new Response <User>(); userResponse.status = "Failed: Not Multipart Content"; userResponse.model = null; return(Ok(userResponse)); } }
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); }