public IEnumerable <cls_room> GetUserRooms(string UserId) { var rooms_id = db.Room_Members.Where(x => x.Member == UserId).Select(x => x.Room_id); List <room> userRooms = new List <room>(); cls_room cls_Room = new cls_room(); foreach (var item in rooms_id) { userRooms.Add(db.rooms.FirstOrDefault(x => x.id == item)); } return(userRooms.Select(x => new cls_room() { id = x.id, name = x.name, photo = x.photo, about = x.about, admin = x.admin }).ToList()); }
public async Task <IHttpActionResult> Postwork_group(work_group work_group) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } /////// Add Chat Room for the Course /////////////////////////////////////////////////////////// IFirebaseClient client = new FirebaseClient(config); cls_room new_room = new cls_room { name = work_group.name, about = "Chat Room for " + work_group.name + " Group", admin = work_group.admin, photo = "" }; PushResponse response = await client.PushAsync("chat/rooms/", new_room); var xcv = response.Result.name; var firstMem = new { mem_id = work_group.admin, //db.AspNetUsers.FirstOrDefault(x => x.UserName == room.adminName).Id, mem_name = db.AspNetUsers.FirstOrDefault(x => x.Id == work_group.admin).UserName //room.adminName }; await PushChat(firstMem, "chat/members/" + xcv); ///////////////////////////// var new_room2 = new { RoomId = xcv, RoomName = new_room.name, about = "Chat room for " + work_group.name + " group", AddedOn = DateTime.UtcNow, RoomType = "group", RelatedTypeId = db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id }; await PushChat(new_room2, "chat/memberRooms/" + work_group.admin); work_group.room_id = xcv; db.work_group.Add(work_group); db.SaveChanges(); Work_group_members wg = new Work_group_members(); wg.Member_id = work_group.admin; wg.Work_group_id = db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id; wg.AddingDate = System.DateTime.Now; db.Work_group_members.Add(wg); db.SaveChanges(); ////////////////////////////////////////////////////////////////////////////////////////////// //send notification to all friends var friends = db.friends.Where(x => x.UserId == work_group.admin && x.Confirmed == true).Select(x => x.friendId); var friends2 = db.friends.Where(x => x.friendId == work_group.admin && x.Confirmed == true).Select(x => x.UserId); friends.Concat(friends2); // var new_notifi = new cls_notifi { source_name = "group", source_id = db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id.ToString(), image = "no image", body_English = "Work group " + work_group.name + " is available now by your friend " + db.AspNetUsers.FirstOrDefault(x => x.Id == work_group.admin).UserName, body_Arabic = "تمت اتاحة مجموعة " + work_group.name + " من قبل صديقك " + db.AspNetUsers.FirstOrDefault(x => x.Id == work_group.admin).UserName, timestamp = DateTime.UtcNow, readed = false }; foreach (var item in friends) { await Push(new_notifi, "notifications/" + item + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy")); PushNotifi(db.AspNetUsers.FirstOrDefault(x => x.Id == item).DeviceToken, "New Workgroup", new_notifi.body_English, "group", db.work_group.OrderByDescending(x => x.id).FirstOrDefault().id.ToString()); } return(CreatedAtRoute("DefaultApi", new { id = work_group.id }, work_group)); }
public async Task <IHttpActionResult> Postcourse(course course) { // course.instructor= if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Course_Members cm = new Course_Members(); course_tags ct = new course_tags(); ct.course_id = course.id; //ct.tag_id= cm.Course_id = course.id; cm.Member_id = course.instructor; cm.AddingDate = course.creating_date; //send notification to all friends var friends = db.friends.Where(x => x.UserId == course.instructor && x.Confirmed == true).Select(x => x.friendId); var friends2 = db.friends.Where(x => x.friendId == course.instructor && x.Confirmed == true).Select(x => x.UserId); friends.Concat(friends2); // var new_notifi = new cls_notifi { source_name = "course", source_id = db.courses.OrderByDescending(x => x.id).FirstOrDefault().id.ToString(), image = "no image", body_English = "Course " + course.name + " is available now by your friend " + db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName, body_Arabic = "تمت اتاحة كورس " + course.name + " من قبل صديقك " + db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName, timestamp = DateTime.UtcNow, readed = false }; foreach (var item in friends) { await Push(new_notifi, "notifications/" + item + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy")); PushNotifi(db.AspNetUsers.FirstOrDefault(x => x.Id == item).DeviceToken, "New Course", new_notifi.body_English, "course", db.courses.OrderByDescending(x => x.id).FirstOrDefault().id.ToString()); } /////// Add Chat Room for the Course /////////////////////////////////////////////////////////// IFirebaseClient client = new FirebaseClient(config); cls_room new_room = new cls_room { name = course.name, about = "Chat Room for " + course.name + " Course", admin = course.instructor, photo = "" }; PushResponse response = await client.PushAsync("chat/rooms/", new_room); var xcv = response.Result.name; var firstMem = new { mem_id = course.instructor, //db.AspNetUsers.FirstOrDefault(x => x.UserName == room.adminName).Id, mem_name = db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName //room.adminName }; await PushChat(firstMem, "chat/members/" + xcv); ///////////////////////////// var new_room2 = new { RoomId = xcv, RoomName = new_room.name, about = "Chat room for " + course.name + " course", AddedOn = DateTime.UtcNow, RoomType = "course", RelatedTypeId = db.courses.OrderByDescending(x => x.id).FirstOrDefault().id }; await PushChat(new_room2, "chat/memberRooms/" + course.instructor); course.room_id = xcv; db.courses.Add(course); db.Course_Members.Add(cm); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = course.id }, course)); }