public ActionResult ShowPostDetail(int postId, String currentUserId, int skip, int take) { var postService = this.Service <IPostService>(); Post post = null; ResponseModel <PostDetailViewModel> response = null; try { post = postService.GetPostById(postId); PostOveralViewModel overal = Mapper.Map <PostOveralViewModel>(post); PreparePostOveralData(overal, currentUserId); PostDetailViewModel result = PreparePostDetailData(overal, skip, take); response = new ResponseModel <PostDetailViewModel>(true, "Chi tiết bài viết:", null, result); } catch (Exception) { response = ResponseModel <PostDetailViewModel> .CreateErrorResponse("Tải bài viết thất bại!", systemError); } return(Json(response)); }
public ActionResult FindUser(String query, int skip, int take) { var service = this.Service <IAspNetUserService>(); ResponseModel <List <AspNetUserOveralViewModel> > response = null; try { List <AspNetUser> userList = service.FindUserByName(query, skip, take).ToList(); userList = FilterMember(userList); List <AspNetUserOveralViewModel> result = new List <AspNetUserOveralViewModel>(); foreach (var user in userList) { result.Add(PrepareAspNetUserOveralViewModel(user)); } response = new ResponseModel <List <AspNetUserOveralViewModel> >(true, "Kết quả tìm kiếm:", null, result); } catch (Exception) { response = ResponseModel <List <AspNetUserOveralViewModel> > .CreateErrorResponse("Tìm kiếm thất bại!", systemError); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult GetAllEvent(string currentUserId, int skip, int take) { var service = this.Service <IEventService>(); ResponseModel <List <EventOveralViewModel> > response = null; try { List <Event> eventList = service.GetAllEvent(skip, take); List <EventOveralViewModel> result = new List <EventOveralViewModel>(); foreach (var e in eventList) { result.Add(PrepareEventForMember(e, currentUserId)); List <Participation> list = e.Participations.ToList(); foreach (var l in list) { if (l.UserId.Equals(currentUserId)) { } } } response = new ResponseModel <List <EventOveralViewModel> >(true, "Danh sách cách sự kiện của bạn:", null, result); } catch (Exception) { response = ResponseModel <List <EventOveralViewModel> > .CreateErrorResponse("Tải danh sách thất bại", systemError); } return(Json(response)); }
public ActionResult ShowPlaceDetail(int id) { ResponseModel <PlaceDetailViewModel> response = null; var service = this.Service <IPlaceService>(); try { Place place = service.GetPlaceById(id); if (place != null) { PlaceDetailViewModel result = Mapper.Map <PlaceDetailViewModel>(place); result.StatusString = Utils.GetEnumDescription((PlaceStatus)result.Status); response = new ResponseModel <PlaceDetailViewModel>(true, "Thông tin địa điểm đã tải thành công", null, result); } else { response = ResponseModel <PlaceDetailViewModel> .CreateErrorResponse("Thất bại khi tải thông tin địa điểm!", systemError); } } catch (Exception) { response = ResponseModel <PlaceDetailViewModel> .CreateErrorResponse("Thất bại khi tải thông tin địa điểm!", systemError); } return(Json(response)); }
public ActionResult MarkAllAsRead(String userId) { var service = this.Service <INotificationService>(); ResponseModel <bool> response = null; try { bool result = service.MarkAllAsRead(userId); if (result) { response = new ResponseModel <bool>(result, "Đã đánh dấu", null); } else { response = new ResponseModel <bool>(result, "Không có thông báo nào để đánh dấu", null); } } catch (Exception) { response = ResponseModel <bool> .CreateErrorResponse("Không thể đánh dấu", systemError); } return(Json(response)); }
public ActionResult ShowNewsDetail(int id) { var service = this.Service <INewsService>(); ResponseModel <NewsViewModel> response = null; try { News news = service.FirstOrDefaultActive(x => x.Id == id); if (news.NumOfRead != null) { news.NumOfRead++; } else { news.NumOfRead = 1; } service.Update(news); service.Save(); NewsViewModel result = Mapper.Map <NewsViewModel>(news); PrepareNewsViewModel(result); response = new ResponseModel <NewsViewModel>(true, "Chi tiết tin tức:", null, result); } catch (Exception) { response = ResponseModel <NewsViewModel> .CreateErrorResponse("Không thể tải tin", systemError); } return(Json(response)); }
public ActionResult ShowAllPlaces(int skip, int take) { ResponseModel <List <PlaceOveralViewModel> > response = null; var service = this.Service <IPlaceService>(); List <Place> placeList = null; try { placeList = service.GetAll(skip, take).ToList(); List <PlaceOveralViewModel> result = Mapper.Map <List <PlaceOveralViewModel> >(placeList); foreach (var place in placeList) { foreach (var r in result) { if (r.Id == place.Id) { r.SportList = GetAllSportOfPlace(place); PreparePlaceOveralViewModel(r); } } } response = new ResponseModel <List <PlaceOveralViewModel> >(true, "Danh sách địa điểm đã tải thành công!", null, result); } catch (Exception) { response = ResponseModel <List <PlaceOveralViewModel> > .CreateErrorResponse("Danh sách địa điểm đã tải thất bại!", systemError); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult ChangeGroupAvatar(int groupId, HttpPostedFileBase image) { var service = this.Service <IGroupService>(); ResponseModel <String> response = null; FileUploader uploader = new FileUploader(); try { String path = null; if (image != null) { path = uploader.UploadImage(image, userImagePath); } String result = service.ChangeAvatarImage(groupId, path); response = new ResponseModel <String>(true, "Ảnh nhóm đã được cập nhật!", null, result); } catch (Exception) { response = ResponseModel <String> .CreateErrorResponse("Ảnh nhóm chưa được cập nhật!", systemError); } return(Json(response)); }
public ActionResult ShowAllJoinedGroup(String userId) { var groupService = this.Service <IGroupService>(); var groupMemberService = this.Service <IGroupMemberService>(); ResponseModel <List <GroupViewModel> > response = null; try { List <GroupMember> joinedList = groupMemberService.GetJoinedList(userId).ToList(); List <Group> groupList = new List <Group>(); foreach (var j in joinedList) { Group group = groupService.FindGroupById(j.GroupId); if (group != null) { groupList.Add(group); } } List <GroupViewModel> result = Mapper.Map <List <GroupViewModel> >(groupList); response = new ResponseModel <List <GroupViewModel> >(true, "Danh sách nhóm:", null, result); } catch (Exception) { response = ResponseModel <List <GroupViewModel> > .CreateErrorResponse("Không thể tải danh sách nhóm", systemError); } return(Json(response)); }
public ActionResult DeleteFieldSchedule(int id) { var service = this.Service <IFieldScheduleService>(); ResponseModel <FieldScheduleViewModel> response = null; try { var schedule = service.Get(id); if (schedule == null) { response = ResponseModel <FieldScheduleViewModel> .CreateErrorResponse("Xóa lịch thất bại", "Lịch sân không tồn tại"); } else { service.Deactivate(schedule); FieldScheduleViewModel result = PrepareFieldScheduleViewModel(schedule); response = new ResponseModel <FieldScheduleViewModel>(true, "Lịch đã được xóa.", null, result); } } catch (Exception) { response = ResponseModel <FieldScheduleViewModel> .CreateErrorResponse("Xóa lịch thất bại", systemError); } return(Json(response)); }
public ActionResult DeleteComment(int id) { var service = this.Service <IPostCommentService>(); ResponseModel <bool> response = null; try { PostComment comment = service.FirstOrDefaultActive(x => x.Id == id); if (comment != null) { service.Deactivate(comment); response = new ResponseModel <bool>(true, "Đã xóa bài viết", null); } else { response = ResponseModel <bool> .CreateErrorResponse("Không thể xóa bài viết", systemError); } } catch (Exception) { response = ResponseModel <bool> .CreateErrorResponse("Không thể xóa bài viết", systemError); } return(Json(response)); }
public ActionResult KickMember(int id) { var service = this.Service <IGroupMemberService>(); ResponseModel <GroupMemberDetailViewModel> response = null; try { GroupMember member = service.KickMember(id); if (member.Active == false) { GroupMemberDetailViewModel result = PrepareGroupMember(member); response = new ResponseModel <GroupMemberDetailViewModel>(true, "Đã đuổi thành viên", null, result); } else { response = ResponseModel <GroupMemberDetailViewModel> .CreateErrorResponse("Đuổi thành viên thất bại", systemError); } } catch (Exception) { response = ResponseModel <GroupMemberDetailViewModel> .CreateErrorResponse("Đuổi thành viên thất bại", systemError); } return(Json(response)); }
public ActionResult LeaveGroup(int groupId, String userId) { var service = this.Service <IGroupMemberService>(); ResponseModel <bool> response = null; try { bool result = service.LeaveGroup(groupId, userId); if (result == false) { response = ResponseModel <bool> .CreateErrorResponse("Thành viên không tồn tại!", systemError); } else { response = new ResponseModel <bool>(result, "Bạn đã rời nhóm!", null); } } catch (Exception) { response = ResponseModel <bool> .CreateErrorResponse("Rời nhóm thất bại!", systemError); } return(Json(response)); }
public ActionResult DeletePost(int id) { var postService = this.Service <IPostService>(); var imageService = this.Service <IPostImageService>(); ResponseModel <bool> response = null; try { Post post = postService.FirstOrDefaultActive(x => x.Id == id); List <PostImage> imageList = post.PostImages.ToList(); if (imageList != null) { foreach (var img in imageList) { imageService.Delete(img); } } postService.Deactivate(post); response = new ResponseModel <bool>(true, "Xóa bài thành công", null); } catch (Exception) { response = ResponseModel <bool> .CreateErrorResponse("Xóa bài thất bại", systemError); } return(Json(response)); }
public ActionResult ShowAllOrderOfUser(String userId) { ResponseModel <List <OrderSimpleViewModel> > response = null; var service = this.Service <IOrderService>(); List <Order> orderList = null; try { orderList = service.GetAllOrderOfUser(userId).ToList <Order>(); List <OrderSimpleViewModel> result = new List <OrderSimpleViewModel>(); foreach (var order in orderList) { result.Add(PrepareOrderSimpleViewModel(order)); } response = new ResponseModel <List <OrderSimpleViewModel> >(true, "Đơn đặt sân của bạn đã được tải thành công!", null, result); } catch (Exception) { response = ResponseModel <List <OrderSimpleViewModel> > .CreateErrorResponse("Đơn đặt sân của bạn đã tải thất bại!", systemError); } return(Json(response)); }
public ActionResult ShowGroupDetail(int id, string currentUser) { var groupService = this.Service <IGroupService>(); var groupMemberService = this.Service <IGroupMemberService>(); ResponseModel <GroupDetailViewModel> response = null; try { Group group = groupService.FindGroupById(id); GroupDetailViewModel result = Mapper.Map <GroupDetailViewModel>(group); result.IsAdmin = groupMemberService.CheckAdmin(currentUser, result.Id); result.IsMember = groupMemberService.CheckMember(currentUser, result.Id); response = new ResponseModel <GroupDetailViewModel>(true, "Thông tin nhóm:", null, result); } catch (Exception) { response = ResponseModel <GroupDetailViewModel> .CreateErrorResponse("Tải thông tin thất bại!", systemError); } return(Json(response)); }
public ActionResult GetReceivedInvitation(string userId) { var invitationService = this.Service <IInvitationService>(); var userInviService = this.Service <IUserInvitationService>(); ResponseModel <List <InvitationViewModel> > response = null; try { List <UserInvitation> list = userInviService.GetActive(x => x.ReceiverId.Equals(userId)).ToList(); List <Invitation> inviList = new List <Invitation>(); foreach (var l in list) { inviList.Add(l.Invitation); } List <InvitationViewModel> result = new List <InvitationViewModel>(); foreach (var invi in inviList) { result.Add(PrepareInvitationViewModelForReceiver(invi, userId)); } response = new ResponseModel <List <InvitationViewModel> >(true, "Lời mời của bạn:", null, result); } catch (Exception) { response = ResponseModel <List <InvitationViewModel> > .CreateErrorResponse("Không thể tải lời mời", systemError); } return(Json(response)); }
public ActionResult CreateGroup(GroupCreateModel model, String userId) { var groupService = this.Service <IGroupService>(); var groupMemberService = this.Service <IGroupMemberService>(); ResponseModel <GroupViewModel> response = null; try { Group group = Mapper.Map <Group>(model); if (model.UploadImage != null) { FileUploader uploader = new FileUploader(); group.Avatar = uploader.UploadImage(model.UploadImage, userImagePath); } group = groupService.CreateGroup(group); groupMemberService.CreateGroupAdmin(group.Id, userId); GroupViewModel result = Mapper.Map <GroupViewModel>(group); response = new ResponseModel <GroupViewModel>(true, "Tạo nhóm thành công", null, result); } catch (Exception) { response = ResponseModel <GroupViewModel> .CreateErrorResponse("Tạo nhóm thất bại!", systemError); } return(Json(response)); }
public ActionResult ChangePlaceStatus(int id, int status) { var service = this.Service <IPlaceService>(); ResponseModel <PlaceOveralViewModel> response = null; try { Place place = service.ChangeStatus(id, status); if (place != null) { PlaceOveralViewModel result = Mapper.Map <PlaceOveralViewModel>(place); PreparePlaceOveralViewModel(result); response = new ResponseModel <PlaceOveralViewModel>(true, "Trạng thái đã được cập nhật!", null, result); } else { response = ResponseModel <PlaceOveralViewModel> .CreateErrorResponse("Cập nhật trạng thái thất bại!", systemError); } } catch (Exception e) { response = ResponseModel <PlaceOveralViewModel> .CreateErrorResponse("Cập nhật trạng thái thất bại!", systemError); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public ActionResult FollowUnfollowUser(String userId, String followerId) { var service = this.Service <IFollowService>(); ResponseModel <bool> response = null; try { bool result = service.FollowUnfollowUser(userId, followerId); if (result) { response = new ResponseModel <bool>(true, "Đã theo dõi", null); } else { response = new ResponseModel <bool>(true, "Đã bỏ theo dõi", null); } } catch (Exception) { response = ResponseModel <bool> .CreateErrorResponse("Theo dõi thất bại", systemError); } return(Json(response)); }
public ActionResult ShowAllPlacesOfPlaceOwner(String ownerId) { ResponseModel <List <PlaceOveralViewModel> > response = null; var service = this.Service <IPlaceService>(); List <PlaceOveralViewModel> result = null; try { List <Place> placeList = service.GetAllOfPlaceOwner(ownerId).ToList(); result = Mapper.Map <List <PlaceOveralViewModel> >(placeList); foreach (var r in result) { PreparePlaceOveralViewModel(r); } response = new ResponseModel <List <PlaceOveralViewModel> >(true, "Danh sách địa điểm của bạn:", null, result); } catch (Exception) { response = ResponseModel <List <PlaceOveralViewModel> > .CreateErrorResponse("Tải danh sách địa điểm thất bại", systemError); } return(Json(response)); }
public ActionResult GetPeopleFollowYou(string userId) { var service = this.Service <IFollowService>(); ResponseModel <List <AspNetUserOveralViewModel> > response = null; try { List <Follow> followList = service.GetActive(x => x.UserId.Equals(userId)).ToList(); List <AspNetUserOveralViewModel> result = new List <AspNetUserOveralViewModel>(); if (followList != null) { foreach (var follow in followList) { result.Add(PreparePeopleFollowYou(follow)); } } response = new ResponseModel <List <AspNetUserOveralViewModel> >(true, "Danh sách những người theo dõi bạn:", null, result); } catch (Exception) { response = ResponseModel <List <AspNetUserOveralViewModel> > .CreateErrorResponse("Tải danh sách theo dõi thất bại", systemError); } return(Json(response)); }
public ActionResult LoadNoti(String userId, int skip, int take) { var service = this.Service <INotificationService>(); ResponseModel <List <NotificationFullInfoViewModel> > response = null; try { List <Notification> notiList = service.GetNoti(userId, skip, take).ToList(); List <NotificationFullInfoViewModel> result = new List <NotificationFullInfoViewModel>(); foreach (var noti in notiList) { result.Add(service.PrepareNoti(PrepareNotificationViewModel(noti))); } response = new ResponseModel <List <NotificationFullInfoViewModel> >(true, "Thông báo mới của bạn:", null, result); } catch (Exception e) { response = ResponseModel <List <NotificationFullInfoViewModel> > .CreateErrorResponse("Không thể tải thông báo", systemError); } return(Json(response)); }
public ActionResult ShowFieldDetail(int id) { ResponseModel <FieldDetailViewModel> response = null; var service = this.Service <IFieldService>(); try { Field field = service.GetFieldInfo(id); if (field != null) { FieldDetailViewModel result = PrepareFieldDetailViewModel(field); response = new ResponseModel <FieldDetailViewModel>(true, "Chi tiết sân:", null, result); } else { response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Tải chi tiết sân thất bại!", systemError); } } catch (Exception) { response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Tải chi tiết sân thất bại!", systemError); } return(Json(response)); }
public ActionResult ChangeCover(String userId, HttpPostedFileBase image) { var service = this.Service <IAspNetUserService>(); ResponseModel <String> response = null; FileUploader uploader = new FileUploader(); try { String path = null; if (image != null) { path = uploader.UploadImage(image, userImagePath); } String result = service.ChangeCover(userId, path); response = new ResponseModel <String>(true, "Ảnh bìa của bạn đã được cập nhật!", null, result); } catch (Exception) { response = ResponseModel <String> .CreateErrorResponse("Ảnh bìa của bạn chưa được cập nhật!", systemError); } return(Json(response)); }
public ActionResult ChangeFieldStatus(int id, int status) { ResponseModel <FieldDetailViewModel> response = null; var service = this.Service <IFieldService>(); try { Field field = service.ChangeFieldStatus(id, status); if (field != null) { FieldDetailViewModel result = PrepareFieldDetailViewModel(field); response = new ResponseModel <FieldDetailViewModel>(true, "Trạng thái sân đã được cập nhật thành công", null, result); } else { response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Cập nhật trạng thái sân thất bại", systemError); } } catch (Exception) { response = ResponseModel <FieldDetailViewModel> .CreateErrorResponse("Cập nhật trạng thái sân thất bại", systemError); } return(Json(response)); }
public ActionResult GetAllEventOfPlaceOwner(String ownerId) { var service = this.Service <IEventService>(); ResponseModel <List <EventOveralViewModel> > response = null; try { List <Event> eventList = service.GetAllPlaceOwnerEvent(ownerId); List <EventOveralViewModel> result = new List <EventOveralViewModel>(); foreach (var e in eventList) { result.Add(PrepareEventOveralViewModel(e)); } response = new ResponseModel <List <EventOveralViewModel> >(true, "Danh sách cách sự kiện của bạn:", null, result); } catch (Exception) { response = ResponseModel <List <EventOveralViewModel> > .CreateErrorResponse("Tải danh sách thất bại", systemError); } return(Json(response)); }
public ActionResult GetAllPostImage(String userId) { var userService = this.Service <IAspNetUserService>(); var imageService = this.Service <IPostImageService>(); ResponseModel <List <PostImageViewModel> > response = null; try { AspNetUser user = userService.FirstOrDefaultActive(x => x.Id == userId); List <Post> postList = user.Posts.ToList(); List <PostImage> imageList = new List <PostImage>(); foreach (var post in postList) { foreach (var img in imageService.GetAllPostImage(post.Id)) { imageList.Add(img); } } List <PostImageViewModel> result = Mapper.Map <List <PostImageViewModel> >(imageList); response = new ResponseModel <List <PostImageViewModel> >(true, "Danh sách hình:", null, result); } catch (Exception) { response = ResponseModel <List <PostImageViewModel> > .CreateErrorResponse("Không thể tải hình", systemError); } return(Json(response)); }
public ActionResult GetComment(int postId, int skip, int take) { var service = this.Service <IPostCommentService>(); ResponseModel <List <PostCommentDetailViewModel> > response = null; try { List <PostComment> commentList = service.GetCommentListByPostId(postId, skip, take).ToList(); List <PostCommentDetailViewModel> result = new List <PostCommentDetailViewModel>(); foreach (var comment in commentList) { result.Add(PreparePostCommentDetailViewModel(comment)); } response = new ResponseModel <List <PostCommentDetailViewModel> >(true, "Tải bình luận thành công", null, result); } catch (Exception) { response = ResponseModel <List <PostCommentDetailViewModel> > .CreateErrorResponse("Tải bình luận thất bại", systemError); } return(Json(response)); }
public ActionResult ShowAllUserPost(String userId, String currentUserId, int skip, int take) { var postService = this.Service <IPostService>(); List <Post> postList = null; ResponseModel <List <PostOveralViewModel> > response = null; try { postList = postService.GetAllProfilePost(userId, skip, take).ToList <Post>(); List <PostOveralViewModel> result = Mapper.Map <List <PostOveralViewModel> >(postList); foreach (var p in result) { PreparePostOveralData(p, currentUserId); } response = new ResponseModel <List <PostOveralViewModel> >(true, "Tải bài viết thành công!", null, result); } catch (Exception) { response = ResponseModel <List <PostOveralViewModel> > .CreateErrorResponse("Tải bài viết thất bại!", systemError); } return(Json(response)); }