Exemple #1
0
        public ActionResult MakeGroupAdmin(int groupId, string curAdminId, string desAdminId)
        {
            var _GroupMemberService  = this.Service <IGroupMemberService>();
            var _notificationService = this.Service <INotificationService>();
            var result = new AjaxOperationResult();

            GroupMember curAdmin = _GroupMemberService.FirstOrDefaultActive(g => g.GroupId == groupId && g.UserId == curAdminId && g.Admin == true);
            GroupMember desAdmin = _GroupMemberService.FirstOrDefaultActive(g => g.GroupId == groupId && g.UserId == desAdminId && g.Admin == false);

            if (curAdmin != null && desAdmin != null)
            {
                //curAdmin.Admin = false;
                desAdmin.Admin = true;

                //_GroupMemberService.Update(curAdmin);
                _GroupMemberService.Update(desAdmin);
                _GroupMemberService.Save();

                //save noti
                string title   = Utils.GetEnumDescription(NotificationType.Other);
                int    type    = (int)NotificationType.GroupMemberAction;
                string message = curAdmin.AspNetUser.FullName + " đã gán quyền quản trị cho bạn trong nhóm " + curAdmin.Group.Name;

                Notification noti = _notificationService.CreateNoti(desAdminId, curAdminId, title, message, type, null, null, null, curAdmin.Group.Id);

                //////////////////////////////////////////////
                //signalR noti
                NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                // Get the context for the Pusher hub
                IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                // Notify clients in the group
                hubContext.Clients.User(notiModel.UserId).send(notiModel);



                //Notification noti = new Notification();
                //noti.UserId = desAdminId;
                //noti.FromUserId = curAdminId;
                //noti.Message = curAdmin.AspNetUser.FullName + " đã gán quyền quản trị cho bạn trong nhóm " + curAdmin.Group.Name;
                //noti.MarkRead = false;
                //noti.Type = (int)NotificationType.Other;
                //noti.Title = Utils.GetEnumDescription(NotificationType.Other);
                //noti.CreateDate = DateTime.Now;
                //_notificationService.Create(noti);
                //_notificationService.Save();


                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
        public ActionResult RejectPlaceOwner(string id)
        {
            var result  = new AjaxOperationResult();
            var service = this.Service <IAspNetUserService>();
            var user    = service.Get(id);

            if (user == null)
            {
                return(this.IdNotFound());
            }
            else
            {
                try
                {
                    user.Status = (int)UserStatus.Unapproved;
                    service.Update(user);
                    //var roleService = this.Service<IAspNetRoleService>();
                    //AspNetRole newRole = roleService.Get(UserRole.Member.ToString("d"));
                    //var roles = UserManager.GetRoles(user.Id).ToArray();
                    ////var oldRoles = Roles.GetRolesForUser(user.UserName);
                    //UserManager.RemoveFromRoles(user.Id, roles);
                    //UserManager.AddToRole(user.Id, newRole.Name);
                    string subject = "[SSN] - Từ chối tài khoản";
                    string body    = "Hi <strong>" + user.FullName + "</strong>" +
                                     ",<br/><br/>Tài khoản của bạn đã bị từ chối vì một số thông tin không hợp lệ." +
                                     "<br/> <strong>Tên tài khoản : " + user.UserName + "</strong>";
                    EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { user.Email }, null, null, subject, body, true);

                    //save noti
                    string title   = Utils.GetEnumDescription(NotificationType.UnApprovePlaceOwner);
                    int    type    = (int)NotificationType.UnApprovePlaceOwner;
                    string message = "Quản trị viên đã từ chối yêu cầu là chủ sân của bạn";

                    var          _notificationService = this.Service <INotificationService>();
                    Notification noti = _notificationService.CreateNoti(id, null, title, message, type, null, null, null, null);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);

                    result.Succeed = true;
                }
                catch (Exception)
                {
                    result.Succeed = false;
                }
            }
            return(Json(result));
        }
        public ActionResult ApprovePlaceOwner(string id)
        {
            var result  = new AjaxOperationResult();
            var service = this.Service <IAspNetUserService>();
            var user    = service.Get(id);

            if (user == null)
            {
                return(this.IdNotFound());
            }
            else
            {
                try
                {
                    user.Status = (int)UserStatus.Active;
                    UserManager.AddToRole(id, Utils.GetEnumDescription(UserRole.PlaceOwner));
                    service.Update(user);
                    string subject = "[SSN] - Chấp nhận tài khoản";
                    string body    = "Hi <strong>" + user.FullName + "</strong>" +
                                     "<br/><br>/Tài khoản của bạn đã được chấp nhận" +
                                     " Vui lòng vào <a href=\"" + Url.Action("Login", "Account", new { area = "" }) + "\">link</a> để đăng nhập" +
                                     "<br/> <strong>Tên tài khoản : " + user.UserName + "</strong>" +
                                     "<br/> Password : Your password" + "</strong>";
                    EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { user.Email }, null, null, subject, body, true);

                    //save noti
                    string title   = Utils.GetEnumDescription(NotificationType.ApprovePlaceOwner);
                    int    type    = (int)NotificationType.ApprovePlaceOwner;
                    string message = "Quản trị viên đã chấp nhận yêu cầu là chủ sân của bạn";

                    var          _notificationService = this.Service <INotificationService>();
                    Notification noti = _notificationService.CreateNoti(id, null, title, message, type, null, null, null, null);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);

                    result.Succeed = true;
                }
                catch (Exception)
                {
                    result.Succeed = false;
                }
            }

            return(Json(result));
        }
Exemple #4
0
        public ActionResult SendChallengeRequest(int fromGroup, int toGroup, string description)
        {
            var       _challengeService = this.Service <IChallengeService>();
            var       _groupService     = this.Service <IGroupService>();
            var       result            = new AjaxOperationResult();
            Challenge cha     = _challengeService.CreateChallengeRequest(fromGroup, toGroup, description);
            string    curUser = User.Identity.GetUserId();

            if (cha != null)
            {
                var _notificationService = this.Service <INotificationService>();
                var _groupMemberService  = this.Service <IGroupMemberService>();

                GroupMember gm  = _groupMemberService.FirstOrDefaultActive(g => g.GroupId == toGroup && g.Admin == true && g.Status == (int)GroupMemberStatus.Approved);
                Group       gu  = _groupService.FirstOrDefaultActive(g => g.Id == toGroup);
                GroupMember fgm = _groupMemberService.FirstOrDefaultActive(g => g.GroupId == fromGroup && g.Admin == true && g.Status == (int)GroupMemberStatus.Approved);
                Group       fgu = _groupService.FirstOrDefaultActive(g => g.Id == fromGroup);
                //save noti
                string title   = Utils.GetEnumDescription(NotificationType.GroupChallengeInvitation);
                int    type    = (int)NotificationType.GroupChallengeInvitation;
                string message = fgu.Name + " đã gửi một lời mời thách đấu cho nhóm " + gu.Name + " của bạn";

                Notification noti = _notificationService.CreateNoti(gm.UserId, curUser, title, message, type, null, null, null, fgm.GroupId);

                //////////////////////////////////////////////
                //signalR noti
                NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                // Get the context for the Pusher hub
                IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                // Notify clients in the group
                hubContext.Clients.User(notiModel.UserId).send(notiModel);


                //Notification noti = new Notification();
                //noti.UserId = gm.UserId;
                ////noti.FromUserId = userId;
                //noti.Title = Utils.GetEnumDescription(NotificationType.Other);
                //noti.Type = (int)NotificationType.Other;
                //noti.Message = fgm.Group.Name + " đã gửi một lời mời thách đấu cho nhóm " + gm.Group.Name;
                //noti.GroupId = gm.Id;
                //noti.CreateDate = DateTime.Now;
                //_notificationService.Create(noti);

                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
Exemple #5
0
        //private NotificationCustomViewModel PrepareNotificationViewModel(Notification noti)
        //{
        //    NotificationCustomViewModel result = Mapper.Map<NotificationCustomViewModel>(noti);

        //    result.CreateDateString = result.CreateDate.ToString("dd/MM/yyyy HH:mm:ss");

        //    result.Avatar = noti.AspNetUser1.AvatarImage;

        //    return result;

        //}

        private NotificationFullInfoViewModel PrepareNotificationViewModel(Notification noti)
        {
            NotificationFullInfoViewModel result = Mapper.Map <NotificationFullInfoViewModel>(noti);

            if (result.CreateDate.HasValue)
            {
                result.CreateDateString = result.CreateDate.Value.Day.ToString("00") + "/" + result.CreateDate.Value.Month.ToString("00") + "/" + result.CreateDate.Value.Year.ToString("0000")
                                          + " lúc " + result.CreateDate.Value.Hour.ToString("00") + ":" + result.CreateDate.Value.Minute.ToString("00");
            }
            else
            {
                result.CreateDateString = "11/11/2016 lúc 00:00";
            }
            return(result);
        }
Exemple #6
0
        public ActionResult ApproveMember(string userId)
        {
            var result = new AjaxOperationResult();
            var _groupMemberService  = this.Service <IGroupMemberService>();
            var _notificationService = this.Service <INotificationService>();

            GroupMember gm = _groupMemberService.ApproveMember(userId);

            if (gm != null)
            {
                //save noti
                string curUser = User.Identity.GetUserId();
                string title   = Utils.GetEnumDescription(NotificationType.Other);
                int    type    = (int)NotificationType.GroupMemberAction;
                string message = "Bạn đã được chấp nhận làm thành viên trong nhóm " + gm.Group.Name;

                Notification noti = _notificationService.CreateNoti(userId, curUser, title, message, type, null, null, null, gm.Group.Id);


                //////////////////////////////////////////////
                //signalR noti
                NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                // Get the context for the Pusher hub
                IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                // Notify clients in the group
                hubContext.Clients.User(notiModel.UserId).send(notiModel);

                //Notification noti = new Notification();
                //noti.UserId = userId;
                //noti.Message = "Bạn đã được chấp nhận làm thành viên trong nhóm " + gm.Group.Name;
                //noti.MarkRead = false;
                //noti.Type = (int)NotificationType.Other;
                //noti.Title = Utils.GetEnumDescription(NotificationType.Other);
                //noti.CreateDate = DateTime.Now;
                //_notificationService.Create(noti);
                //_notificationService.Save();

                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
        public NotificationFullInfoViewModel PrepareNoti(NotificationFullInfoViewModel model)
        {
            NotificationController controller = new NotificationController();

            model.AspNetUser = controller.GetUser(model.UserId);

            model.AspNetUser1 = controller.GetUser(model.FromUserId);
            if (model.CreateDate.HasValue)
            {
                model.CreateDateString = model.CreateDate.Value.Day.ToString("00") + "/" + model.CreateDate.Value.Month.ToString("00") + "/" + model.CreateDate.Value.Year.ToString("0000")
                                         + " lúc " + model.CreateDate.Value.Hour.ToString("00") + ":" + model.CreateDate.Value.Minute.ToString("00");
            }
            else
            {
                model.CreateDateString = "11/11/2016 lúc 00:00";
            }
            return(model);
        }
        //create group post
        public ActionResult CreateGroupPost(string content, String sportSelect, IEnumerable <HttpPostedFileBase> uploadImages, int groupId)
        {
            var result         = new AjaxOperationResult <PostGeneralViewModel>();
            var _postService   = this.Service <IPostService>();
            var _notiService   = this.Service <INotificationService>();
            var _memberService = this.Service <IGroupMemberService>();
            var _userService   = this.Service <IAspNetUserService>();
            var _groupService  = this.Service <IGroupService>();

            var  post        = new Post();
            int  ImageNumber = 0;
            bool hasText     = false;

            post.Active                = true;
            post.CreateDate            = DateTime.Now;
            post.LatestInteractionTime = post.CreateDate;
            post.UserId                = User.Identity.GetUserId();
            post.GroupId               = groupId;

            if (uploadImages != null)
            {
                if (uploadImages.ToList()[0] != null && uploadImages.ToList().Count > 0)
                {
                    if (uploadImages.ToList().Count == 1)
                    {
                        ImageNumber = 1;
                    }
                    else
                    {
                        ImageNumber = 2;
                    }
                }
            }

            if (!String.IsNullOrEmpty(content))
            {
                hasText = true;
            }

            post.PostContent = content;
            if (ImageNumber == 0 && hasText)
            {
                post.ContentType = (int)ContentPostType.TextOnly;
            }
            else if (ImageNumber == 1 && hasText)
            {
                post.ContentType = (int)ContentPostType.TextAndImage;
            }
            else if (ImageNumber == 2 && hasText)
            {
                post.ContentType = (int)ContentPostType.TextAndMultiImages;
            }
            else if (ImageNumber == 1 && !hasText)
            {
                post.ContentType = (int)ContentPostType.ImageOnly;
            }
            else if (ImageNumber == 2 && !hasText)
            {
                post.ContentType = (int)ContentPostType.MultiImages;
            }
            _postService.Create(post);
            _postService.Save();

            if (post.GroupId != null)
            {
                List <GroupMember> memberList = _memberService.GetActive(x => x.GroupId == post.GroupId).ToList();

                AspNetUser postedUser = _userService.FirstOrDefaultActive(x => x.Id.Equals(post.UserId));

                foreach (var member in memberList)
                {
                    if (!(member.UserId.Equals(post.UserId)))
                    {
                        Group        g    = _groupService.FindGroupById(groupId);
                        Notification noti = _notiService.CreateNoti(member.UserId, post.UserId, Utils.GetEnumDescription(NotificationType.GroupPost), postedUser.FullName + " đã đăng một bài viết trong nhóm " + g.Name, (int)NotificationType.GroupPost, post.Id, null, null, groupId);

                        List <string> registrationIds = GetToken(member.UserId);

                        NotificationModel notiModel = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(noti));

                        if (registrationIds != null && registrationIds.Count != 0)
                        {
                            Android.Notify(registrationIds, null, notiModel);
                        }

                        //signalR noti
                        NotificationFullInfoViewModel notiModelR = _notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                        // Get the context for the Pusher hub
                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                        // Notify clients in the group
                        hubContext.Clients.User(notiModel.UserId).send(notiModelR);
                    }
                }
            }

            if (uploadImages != null)
            {
                if (uploadImages.ToList()[0] != null && uploadImages.ToList().Count > 0)
                {
                    var _postImageService = this.Service <IPostImageService>();
                    _postImageService.saveImage(post.Id, uploadImages);
                }
            }
            if (!String.IsNullOrEmpty(sportSelect))
            {
                string[] sportId = sportSelect.Split(',');
                if (sportId != null)
                {
                    var _postSport = this.Service <IPostSportService>();
                    var postSport  = new PostSport();
                    foreach (var item in sportId)
                    {
                        if (!item.Equals(""))
                        {
                            postSport.PostId  = post.Id;
                            postSport.SportId = Int32.Parse(item);
                            _postSport.Create(postSport);
                        }
                    }
                }
            }

            result.AdditionalData = Mapper.Map <PostGeneralViewModel>(post);
            return(Json(result));
        }
        //create profile post
        public ActionResult CreateProfilePost(string content, String sportSelect, IEnumerable <HttpPostedFileBase> uploadImages, string userId, string profileId)
        {
            var  result       = new AjaxOperationResult <PostGeneralViewModel>();
            var  _postService = this.Service <IPostService>();
            var  post         = new Post();
            int  ImageNumber  = 0;
            bool hasText      = false;

            post.Active                = true;
            post.CreateDate            = DateTime.Now;
            post.LatestInteractionTime = DateTime.Now;
            post.UserId                = userId;
            post.ProfileId             = profileId;

            if (uploadImages != null)
            {
                if (uploadImages.ToList()[0] != null && uploadImages.ToList().Count > 0)
                {
                    if (uploadImages.ToList().Count == 1)
                    {
                        ImageNumber = 1;
                    }
                    else
                    {
                        ImageNumber = 2;
                    }
                }
            }

            if (!String.IsNullOrEmpty(content))
            {
                hasText = true;
            }

            post.PostContent = content;
            if (ImageNumber == 0 && hasText)
            {
                post.ContentType = (int)ContentPostType.TextOnly;
            }
            else if (ImageNumber == 1 && hasText)
            {
                post.ContentType = (int)ContentPostType.TextAndImage;
            }
            else if (ImageNumber == 2 && hasText)
            {
                post.ContentType = (int)ContentPostType.TextAndMultiImages;
            }
            else if (ImageNumber == 1 && !hasText)
            {
                post.ContentType = (int)ContentPostType.ImageOnly;
            }
            else if (ImageNumber == 2 && !hasText)
            {
                post.ContentType = (int)ContentPostType.MultiImages;
            }
            _postService.Create(post);
            _postService.Save();
            if (uploadImages != null)
            {
                if (uploadImages.ToList()[0] != null && uploadImages.ToList().Count > 0)
                {
                    var _postImageService = this.Service <IPostImageService>();
                    _postImageService.saveImage(post.Id, uploadImages);
                }
            }
            if (!String.IsNullOrEmpty(sportSelect))
            {
                string[] sportId = sportSelect.Split(',');
                if (sportId != null)
                {
                    var _postSport = this.Service <IPostSportService>();
                    var postSport  = new PostSport();
                    foreach (var item in sportId)
                    {
                        if (!item.Equals(""))
                        {
                            postSport.PostId  = post.Id;
                            postSport.SportId = Int32.Parse(item);
                            _postSport.Create(postSport);
                        }
                    }
                }
            }

            //send noti when others post to your profile
            if (userId != profileId)
            {
                var _notificationService = this.Service <INotificationService>();
                var _userService         = this.Service <IAspNetUserService>();

                AspNetUser sender = _userService.FindUser(userId);

                string title   = Utils.GetEnumDescription(NotificationType.Post);
                int    type    = (int)NotificationType.Post;
                string message = sender.FullName + " đã đăng một bài viết lên tường nhà bạn";

                Notification noti = _notificationService.CreateNoti(profileId, userId, title, message, type, post.Id, null, null, null);

                //////////////////////////////////////////////
                //signalR noti
                NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                // Get the context for the Pusher hub
                IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                // Notify clients in the group
                hubContext.Clients.User(notiModel.UserId).send(notiModel);
            }

            result.AdditionalData = Mapper.Map <PostGeneralViewModel>(post);
            return(Json(result));
        }
Exemple #10
0
        public ActionResult AddFriendGroup(string AddFriendToGroupList, string userId, int groupId, string admin)
        {
            var  result = new AjaxOperationResult();
            var  _notificationService = this.Service <INotificationService>();
            bool isAdmin = Convert.ToBoolean(admin);

            if (!String.IsNullOrEmpty(AddFriendToGroupList))
            {
                string[] frd = AddFriendToGroupList.Split(',');
                if (frd != null)
                {
                    var _userService        = this.Service <IAspNetUserService>();
                    var _groupService       = this.Service <IGroupService>();
                    var _groupMemberService = this.Service <IGroupMemberService>();

                    AspNetUser fromUser = _userService.FindUser(userId);
                    Group      group    = _groupService.FindGroupById(groupId);

                    foreach (var item in frd)
                    {
                        if (!item.Equals(""))
                        {
                            if (isAdmin)
                            {
                                //add to group
                                if (_groupMemberService.JoinGroupByAdmin(groupId, item))
                                {
                                    //save noti
                                    string title   = Utils.GetEnumDescription(NotificationType.GroupInvitation);
                                    int    type    = (int)NotificationType.GroupInvitation;
                                    string message = fromUser.FullName + " đã mời bạn vào nhóm " + group.Name;

                                    Notification noti = _notificationService.CreateNoti(item, userId, title, message, type, null, null, null, group.Id);


                                    //////////////////////////////////////////////
                                    //signalR noti
                                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                                    // Get the context for the Pusher hub
                                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                                    // Notify clients in the group
                                    hubContext.Clients.User(notiModel.UserId).send(notiModel);

                                    //Notification noti = new Notification();
                                    //noti.UserId = item;
                                    //noti.FromUserId = userId;
                                    //noti.Title = Utils.GetEnumDescription(NotificationType.Invitation);
                                    //noti.Type = (int)NotificationType.Invitation;
                                    //noti.Message = fromUser.FullName + " đã mời bạn vào nhóm " + group.Name;
                                    //noti.GroupId = group.Id;
                                    //noti.CreateDate = DateTime.Now;
                                    //noti.MarkRead = false;
                                    //_notificationService.Create(noti);
                                    result.Succeed = true;
                                }
                                else
                                {
                                    result.Succeed = false;
                                }
                            }
                            else
                            {
                                //add to group
                                if (_groupMemberService.JoinGroup(groupId, item))
                                {
                                    //save noti
                                    string title   = Utils.GetEnumDescription(NotificationType.GroupInvitation);
                                    int    type    = (int)NotificationType.GroupInvitation;
                                    string message = fromUser.FullName + " đã mời bạn vào nhóm " + group.Name;

                                    Notification noti = _notificationService.CreateNoti(item, userId, title, message, type, null, null, null, group.Id);


                                    //////////////////////////////////////////////
                                    //signalR noti
                                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                                    // Get the context for the Pusher hub
                                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                                    // Notify clients in the group
                                    hubContext.Clients.User(notiModel.UserId).send(notiModel);

                                    //Notification noti = new Notification();
                                    //noti.UserId = item;
                                    //noti.FromUserId = userId;
                                    //noti.Title = Utils.GetEnumDescription(NotificationType.Invitation);
                                    //noti.Type = (int)NotificationType.Invitation;
                                    //noti.Message = fromUser.FullName + " đã mời bạn vào nhóm " + group.Name;
                                    //noti.GroupId = group.Id;
                                    //noti.CreateDate = DateTime.Now;
                                    //noti.MarkRead = false;
                                    //_notificationService.Create(noti);
                                    result.Succeed = true;
                                }
                                else
                                {
                                    result.Succeed = false;
                                }
                            }
                        }
                        else
                        {
                            result.Succeed = false;
                        }
                    }
                }
                else
                {
                    result.Succeed = false;
                }
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
Exemple #11
0
        public ActionResult CreateInvitation(string[] userId, string sportSelect, string inviteContent, string orderInfo, string groupChatName)
        {
            var    result = new AjaxOperationResult <InvitationViewModel>();
            var    userInvitationService = this.Service <IUserInvitationService>();
            var    invitationService     = this.Service <IInvitationService>();
            var    orderService          = this.Service <IOrderService>();
            var    userService           = this.Service <IAspNetUserService>();
            var    curUserId             = User.Identity.GetUserId();
            var    curUser     = userService.FirstOrDefaultActive(p => p.Id == curUserId);
            var    notiService = this.Service <INotificationService>();
            string content     = "";

            if (orderInfo != null && orderInfo != "")
            {
                var order = orderService.FirstOrDefaultActive(p => p.OrderCode == orderInfo);
                content = " .Thời gian: " + order.StartTime.ToString("HH:mm") + " - " + order.EndTime.ToString("HH:mm")
                          + " Ngày " + order.StartTime.ToString("dd/MM/yyyy") + ". Tại sân: " + order.Field.Name + " ,địa điểm: "
                          + order.Field.Place.Name;
            }
            Invitation invi = new Invitation();

            invi.SenderId          = curUserId;
            invi.InvitationContent = inviteContent + content;
            invi.CreateDate        = DateTime.Now;
            invi.Active            = true;
            if (groupChatName == null || groupChatName == "")
            {
                groupChatName = "Không tiêu đề";
            }
            invi.Subject = groupChatName;
            invitationService.Create(invi);
            for (int i = 0; i < userId.Length; i++)
            {
                var isDup = false;
                for (int count = 0; count < i; count++)
                {
                    if (userId[i] == userId[count])
                    {
                        isDup = true;
                        break;
                    }
                }
                if (!isDup)
                {
                    UserInvitation UIn  = new UserInvitation();
                    Notification   noti = new Notification();
                    UIn.InvitationId = invi.Id;
                    UIn.ReceiverId   = userId[i];
                    UIn.Active       = true;
                    userInvitationService.Create(UIn);
                    noti.InvitationId = UIn.InvitationId;
                    noti.UserId       = userId[i];
                    noti.FromUserId   = curUserId;
                    noti.CreateDate   = DateTime.Now;
                    noti.Active       = true;
                    noti.Type         = (int)NotificationType.Invitation;
                    noti.Message      = curUser.FullName + " đã gửi lời mời bạn cùng chơi thể thao";
                    noti.Title        = "Invite";
                    noti.MarkRead     = false;
                    notiService.Create(noti);

                    //Fire base noti
                    List <string> registrationIds = GetToken(userId[i]);

                    //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                    NotificationModel amodel = Mapper.Map <NotificationModel>(PrepareNotificationViewModel(noti));

                    if (registrationIds != null && registrationIds.Count != 0)
                    {
                        Android.Notify(registrationIds, null, amodel);
                    }


                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);
                }
            }
            InvitationViewModel model = Mapper.Map <InvitationViewModel>(invi);

            model.Host            = curUser.FullName;
            result.AdditionalData = model;
            result.Succeed        = true;
            return(Json(result));
        }
Exemple #12
0
        public ActionResult UpdateChallenge(int challengeId, int status)
        {
            var _challengeService = this.Service <IChallengeService>();
            var result            = new AjaxOperationResult();

            if (_challengeService.UpdateChallenge(challengeId, status) == true)
            {
                Challenge cha = _challengeService.FindById(challengeId);
                ChallengeDetailViewModel chaVM = Mapper.Map <ChallengeDetailViewModel>(cha);
                string curUser = User.Identity.GetUserId();
                //save noti
                var    _notificationService = this.Service <INotificationService>();
                var    _groupMemberService  = this.Service <IGroupMemberService>();
                string title   = "";
                int    type    = -1;
                string message = "";

                switch (status)
                {
                case (int)ChallengeStatus.NotOperate:
                    GroupMember gm = _groupMemberService.FirstOrDefaultActive(g => g.GroupId == cha.Group.Id && g.Admin == true && g.Status == (int)GroupMemberStatus.Approved);
                    //save noti
                    title   = Utils.GetEnumDescription(NotificationType.GroupChallengeInvitation);
                    type    = (int)NotificationType.GroupChallengeInvitation;
                    message = "Nhóm " + chaVM.Group1.Name + " đã đồng ý lời thách đấu từ nhóm " + cha.Group.Name + " của bạn";
                    Notification noti = _notificationService.CreateNoti(gm.UserId, curUser, title, message, type, null, null, null, cha.Group1.Id);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);
                    break;

                case (int)ChallengeStatus.NotAvailable:
                    GroupMember gm1 = _groupMemberService.FirstOrDefaultActive(g => g.GroupId == cha.Group.Id && g.Admin == true && g.Status == (int)GroupMemberStatus.Approved);
                    //save noti
                    title   = Utils.GetEnumDescription(NotificationType.GroupChallengeInvitation);
                    type    = (int)NotificationType.GroupChallengeInvitation;
                    message = "Nhóm " + chaVM.Group1.Name + " đã từ chối lời thách đấu từ nhóm " + cha.Group.Name + " của bạn";
                    Notification noti1 = _notificationService.CreateNoti(gm1.UserId, curUser, title, message, type, null, null, null, cha.Group1.Id);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel1 = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti1));

                    // Get the context for the Pusher hub
                    IHubContext hubContext1 = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext1.Clients.User(notiModel1.UserId).send(notiModel1);
                    break;
                }
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
Exemple #13
0
        public ActionResult CreateOrder(CreateOrderViewModel model)
        {
            ResponseModel <OrderSimpleViewModel> response = null;

            var orderService = this.Service <IOrderService>();

            var fieldService = this.Service <IFieldService>();

            var userService = this.Service <IAspNetUserService>();

            DateTime startTime = new DateTime();

            DateTime endTime = new DateTime();

            DateTime playDate = new DateTime();

            try
            {
                startTime = DateTime.ParseExact(model.StartTime, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

                endTime = DateTime.ParseExact(model.EndTime, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

                playDate = DateTime.ParseExact(model.PlayDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                response = ResponseModel <OrderSimpleViewModel> .CreateErrorResponse("Đặt sân thất bại", "Lỗi định dạng thời gian");

                return(Json(response));
            }

            if (!CheckTimeValid(model.FieldId, startTime.TimeOfDay, endTime.TimeOfDay))
            {
                response = ResponseModel <OrderSimpleViewModel> .CreateErrorResponse("Đặt sân thất bại", "Thời gian không nằm trong các khung giờ");

                return(Json(response));
            }
            else if (!CheckOrderTime(model.FieldId, startTime.TimeOfDay, endTime.TimeOfDay, playDate, playDate))
            {
                response = ResponseModel <OrderSimpleViewModel> .CreateErrorResponse("Đặt sân thất bại", "Sân đặt được đặt vào thời gian này");

                return(Json(response));
            }
            double price = CalculatePrice(model.FieldId, startTime.TimeOfDay, endTime.TimeOfDay);

            try
            {
                //Get current user info
                var user = userService.FindUser(model.UserId);

                //Create order info
                String orderCode = DateTime.Now.ToString("yyyyMMddHHmmss");

                Order order = new Order();

                order.FieldId    = model.FieldId;
                order.UserId     = model.UserId;
                order.StartTime  = startTime;
                order.EndTime    = endTime;
                order.CreateDate = DateTime.Now;
                order.Price      = price;
                order.Note       = model.Note;
                order.PayerName  = model.PayerName;
                order.PayerEmail = model.PayerEmail;
                order.PayerPhone = model.PayerPhone;
                order.Status     = (int)OrderStatus.Pending;
                order.OrderCode  = orderCode;
                order.QRCodeUrl  = Utils.GenerateQRCode(orderCode, QRCodeGenerator.ECCLevel.Q);
                var transdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                order.TransactionTime = DateTime.Parse(transdate);

                if (model.PaidType == (int)OrderPaidType.ChosePayOnline)
                {
                    order.PaidType = (int)OrderPaidType.ChosePayOnline;
                }
                if (model.PaidType == (int)OrderPaidType.ChosePayByCash)
                {
                    order.PaidType = (int)OrderPaidType.ChosePayByCash;
                }


                //Create Noti
                var field = fieldService.FirstOrDefaultActive(p => p.Id == order.FieldId);
                var noti  = new Notification();
                noti.UserId  = field.Place.UserId;
                noti.Message = user.UserName + " đã đặt sân tại " + field.Name;
                noti.Title   = "Đơn hàng mới";
                noti.Type    = (int)NotificationType.Order;
                noti.Active  = true;
                order.Notifications.Add(noti);


                //Save Order
                order = orderService.CreateOrder(order);


                //Send Email
                string subject = "[SSN] - Thông tin đặt sân";
                string body    = "Hi <strong>" + user.UserName + "</strong>" +
                                 ",<br/><br/>Bạn đã đặt sân: " + field.Name + "<br/> Thời gian: " + order.StartTime.ToString("HH:mm") + " - " +
                                 order.EndTime.ToString("HH:mm") + ", ngày " + order.StartTime.ToString("dd/MM/yyyy") +
                                 "<br/> Giá tiền : " + order.Price + " đồng" +
                                 "<br/> <strong>Mã đặt sân của bạn : " + order.OrderCode + "</strong>" +
                                 "<br/><img src='" + Utils.GetHostName() + order.QRCodeUrl + "'>" +
                                 "<br/> Cảm ơn bạn đã sử dụng dịch vụ của SSN. Chúc bạn có những giờ phút thoải mái chơi thể thao!";
                EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { user.Email }, null, null, subject, body, true);

                OrderSimpleViewModel result = PrepareOrderSimpleViewModel(order);

                response = new ResponseModel <OrderSimpleViewModel>(true, "Đặt sân thành công", null, result);


                //Fire base noti
                List <string> registrationIds = GetToken(noti.UserId);

                //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                NotificationModel Amodel = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(noti));

                if (registrationIds != null && registrationIds.Count != 0)
                {
                    Android.Notify(registrationIds, null, Amodel);
                }

                //SignalR Noti
                var notiService = this.Service <INotificationService>();
                NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                // Get the context for the Pusher hub
                IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                // Notify clients in the group
                hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
            }
            catch (Exception)
            {
                response = ResponseModel <OrderSimpleViewModel> .CreateErrorResponse("Đặt sân thất bại", systemError);
            }

            return(Json(response));
        }
Exemple #14
0
        public ActionResult LikeUnlikePost(int postId, String userId)
        {
            var likeService = this.Service <ILikeService>();

            var notiService = this.Service <INotificationService>();

            var userService = this.Service <IAspNetUserService>();

            var postService = this.Service <IPostService>();

            var postCommentService = this.Service <IPostCommentService>();

            ResponseModel <Like> response = null;

            try
            {
                AspNetUser user = userService.FirstOrDefaultActive(x => x.Id == userId);

                bool createNoti = false;

                Like like = likeService.FirstOrDefault(x => x.PostId == postId && x.UserId == userId);

                if (like == null && GetPostUserId(postId) != user.Id)
                {
                    createNoti = true;
                }

                like = likeService.LikeUnlikePost(postId, userId);

                bool result = like.Active;

                if (result)
                {
                    response = new ResponseModel <Like>(true, "Đã thích", null);
                    if (createNoti)
                    {
                        //get all relative user of this post
                        List <string> AllRelativeUserIdOfPost = new List <string>();

                        List <PostComment> listPostCmt = postCommentService.GetAllRelativeCmtDistinct(postId).ToList();

                        List <Like> listPostLike = likeService.GetAllRelativeLikeDistinct(postId).ToList();

                        foreach (var item in listPostCmt)
                        {
                            AllRelativeUserIdOfPost.Add(item.UserId);
                        }

                        foreach (var item in listPostLike)
                        {
                            AllRelativeUserIdOfPost.Add(item.UserId);
                        }

                        AllRelativeUserIdOfPost = AllRelativeUserIdOfPost.Distinct().ToList();
                        //end=================


                        Post post = postService.FirstOrDefaultActive(x => x.Id == postId);
                        //noti to post creator
                        if (!(post.UserId.Equals(userId)))
                        {
                            Notification notiForPostCreator = notiService.SaveNoti(post.UserId, userId, "Like", user.FullName + " đã thích bài viết của bạn", (int)NotificationType.Post, post.Id, null, null);

                            //Fire base noti
                            List <string> registrationIds = GetToken(user.Id);

                            //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                            NotificationModel model = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(notiForPostCreator));

                            if (registrationIds != null && registrationIds.Count != 0)
                            {
                                Android.Notify(registrationIds, null, model);
                            }


                            //SignalR Noti
                            NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(notiForPostCreator));

                            // Get the context for the Pusher hub
                            IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                            // Notify clients in the group
                            hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
                        }


                        //noti to all user that relavtive in this post
                        foreach (var item in AllRelativeUserIdOfPost)
                        {
                            if (!(item.Equals(userId)) && !(item.Equals(post.UserId)))
                            {
                                Notification not = notiService.SaveNoti(item, userId, "Like", user.FullName + " đã thích bài viết mà bạn theo dõi", (int)NotificationType.Post, post.Id, null, null);

                                Notification noti = notiService.FirstOrDefaultActive(n => n.Id == not.Id);

                                //Fire base noti
                                List <string> registrationIds = GetToken(item);

                                //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                                NotificationModel model = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(noti));

                                if (registrationIds != null && registrationIds.Count != 0)
                                {
                                    Android.Notify(registrationIds, null, model);
                                }


                                //SignalR Noti
                                NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                                // Get the context for the Pusher hub
                                IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                                // Notify clients in the group
                                hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
                            }
                        }

                        post.LatestInteractionTime = DateTime.Now;
                        postService.Update(post);
                        postService.Save();
                        //post.LatestInteractionTime = DateTime.Now;

                        //Notification noti = notiService.SaveNoti(GetPostUserId(postId), userId, "Like", user.FullName + " đã thích bài viết của bạn", (int)NotificationType.Post, postId, null, null);

                        //List<string> registrationIds = GetToken(GetPostUserId(postId));

                        ////registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                        //if (registrationIds != null && registrationIds.Count != 0)
                        //{
                        //    NotificationModel model = Mapper.Map<NotificationModel>(PrepareNotificationCustomViewModel(noti));

                        //    Android.Notify(registrationIds, null, model);

                        //    //signalR noti
                        //    NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map<NotificationFullInfoViewModel>(noti));

                        //    // Get the context for the Pusher hub
                        //    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<RealTimeHub>();

                        //    // Notify clients in the group
                        //    hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
                        //}
                    }
                }
                else
                {
                    response = new ResponseModel <Like>(true, "Đã bỏ thích", null);
                }
            }
            catch (Exception)
            {
                response = ResponseModel <Like> .CreateErrorResponse("Thao tác thất bại!", systemError);
            }
            return(Json(response));
        }
Exemple #15
0
        public ActionResult btnSubmit_Click(object sender, EventArgs e, OrderViewModel model)
        {
            String transaction_info = "Thanh toan dat san";
            String order_code       = DateTime.Now.ToString("yyyyMMddHHmmss");
            String receiver         = "*****@*****.**";//Tài khoản nhận tiền
            String return_url       = Url.Action("verifyOrder", "Order",
                                                 new { area = "", orderCode = order_code }, Request.Url.Scheme);
            String cancel_url = "http://ssn.techeco.net/Order";
            //String price = model.Price.ToString();
            String      price = "2000";
            NL_Checkout nl    = new NL_Checkout();
            String      url;

            url = nl.buildCheckoutUrl(return_url, cancel_url, receiver, transaction_info, order_code, price);

            var      _orderService     = this.Service <IOrderService>();
            var      _timeBlockService = this.Service <ITimeBlockService>();
            var      order             = new Order();
            DateTime PlayDate          = DateTime.ParseExact(Request["CreateDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);

            order.UserId  = User.Identity.GetUserId();
            order.FieldId = model.FieldId;
            DateTime sTime = new DateTime(PlayDate.Year, PlayDate.Month, PlayDate.Day, model.StartTime.Hour,
                                          model.StartTime.Minute, model.StartTime.Second);
            DateTime eTime = new DateTime(PlayDate.Year, PlayDate.Month, PlayDate.Day, model.EndTime.Hour,
                                          model.EndTime.Minute, model.EndTime.Second);

            order.StartTime  = sTime;
            order.EndTime    = eTime;
            order.CreateDate = DateTime.Now;
            //order.Token = result.Token;
            order.Price = _timeBlockService.calPrice(model.FieldId, sTime.TimeOfDay, eTime.TimeOfDay);
            //order.OnlinePaymentMethod = info.Payment_method;
            //order.BankCode = info.bank_code;
            order.Note       = model.Note;
            order.PayerName  = model.PayerName;
            order.PayerEmail = model.PayerEmail;
            order.PayerPhone = model.PayerPhone;
            order.Status     = (int)OrderStatus.Pending;
            order.OrderCode  = order_code;
            order.QRCodeUrl  = Utils.GenerateQRCode(order_code, QRCodeGenerator.ECCLevel.Q);
            var transdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

            order.TransactionTime = DateTime.Parse(transdate);

            if (model.PaidType == (int)OrderPaidType.ChosePayOnline)
            {
                order.PaidType = (int)OrderPaidType.ChosePayOnline;
            }
            if (model.PaidType == (int)OrderPaidType.ChosePayByCash)
            {
                order.PaidType = (int)OrderPaidType.ChosePayByCash;
                url            = Url.Action("BookFieldSuccessful", "Order",
                                            new { area = "", orderCode = order_code }, Request.Url.Scheme);
            }

            var _userService = this.Service <IAspNetUserService>();
            var userId       = User.Identity.GetUserId();
            var user         = _userService.FirstOrDefaultActive(p => p.Id == userId);

            if (user == null)
            {
                return(RedirectToAction("PageNotFound", "Errors"));
            }

            var _fieldService = this.Service <IFieldService>();
            var field         = _fieldService.FirstOrDefaultActive(p => p.Id == order.FieldId);

            if (field == null)
            {
                return(RedirectToAction("PageNotFound", "Errors"));
            }
            var noti = new Notification();

            noti.UserId     = field.Place.UserId;
            noti.FromUserId = userId;
            noti.CreateDate = DateTime.Now;
            noti.Message    = user.FullName + " đã đặt sân tại " + field.Name;
            noti.Title      = "Đơn hàng mới";
            noti.Type       = (int)NotificationType.Order;
            noti.MarkRead   = false;
            noti.Active     = true;
            order.Notifications.Add(noti);
            _orderService.Create(order);


            //Fire base noti
            List <string> registrationIds = GetToken(noti.UserId);

            //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

            NotificationModel Amodel = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(noti));

            if (registrationIds != null && registrationIds.Count != 0)
            {
                Android.Notify(registrationIds, null, Amodel);
            }

            //SignalR Noti
            var notiService = this.Service <INotificationService>();
            NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

            // Get the context for the Pusher hub
            IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

            // Notify clients in the group
            hubContext.Clients.User(notiModelR.UserId).send(notiModelR);


            string subject = "[SSN] - Thông tin đặt sân";
            string body    = "Hi <strong>" + user.FullName + "</strong>" +
                             ",<br/><br/>Bạn đã đặt sân: " + field.Name + "<br/> Tại địa điểm: " + field.Place.Name +
                             "<br/> Thời gian: " + order.StartTime.ToString("HH:mm") + " - " +
                             order.EndTime.ToString("HH:mm") + ", ngày " + order.StartTime.ToString("dd/MM/yyyy") +
                             "<br/> Giá tiền : " + order.Price.ToString("n0") + " đồng" +
                             "<br/> <strong>Mã đặt sân của bạn : " + order.OrderCode + "</strong>" +
                             "<br/><img src='ssn.techeco.net/" + order.QRCodeUrl + "'>" +
                             "<br/> Cảm ơn bạn đã sử dụng dịch vụ của SSN. Chúc bạn có những giờ phút thoải mái chơi thể thao!";

            EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { model.PayerEmail }, null, null, subject, body, true);

            return(Redirect(url));
        }
Exemple #16
0
        public string updateStatusOrder(int id, int status, string reason)
        {
            var _orderService        = this.Service <IOrderService>();
            var _userService         = this.Service <IAspNetUserService>();
            var _notificationService = this.Service <INotificationService>();


            Order order = _orderService.ChangeOrderStatus(id, status);

            if (order != null)
            {
                if (status == (int)OrderStatus.CheckedIn)
                {
                    return("success");
                }
                else
                {
                    //save noti
                    Notification noti = new Notification();
                    noti.UserId     = order.UserId;
                    noti.FromUserId = User.Identity.GetUserId();
                    noti.Title      = Utils.GetEnumDescription(NotificationType.Order);
                    noti.Type       = (int)NotificationType.OrderAction;
                    noti.CreateDate = DateTime.Now;
                    //send mail
                    string receiverEmail = _userService.FirstOrDefaultActive(u => u.Id.Equals(order.UserId)).Email;
                    string subject       = "";
                    string body          = "";
                    if (status == (int)OrderStatus.Approved)
                    {
                        subject = "SSN - Đơn đặt sân được chấp nhận";
                        body    = "<p>Đơn đặt sân <strong>" + order.Field.Name + "</strong> từ <strong>" + order.StartTime.ToString() + "</trong> đến <strong>" + order.EndTime.ToString() + "</strong> đã được chấp nhận</p>"
                                  + "<p>Quý khách vui lòng đến sân <strong>30 phút</strong> trước giờ đặt để xác nhận.</p>"
                                  + "<p>Chúc quý khách có được những giây phút thư giãn vui vẻ!</p>";

                        noti.Message = "Đơn đặt sân " + order.Field.Name + "(" + order.StartTime.ToString() + " - " + order.EndTime.ToString() + ") đã được chấp nhận";
                    }
                    if (status == (int)OrderStatus.Unapproved)
                    {
                        subject = "SSN - Đơn đặt sân đã bị từ chối";
                        body    = "<p>Đơn đặt sân <strong>" + order.Field.Name + "</strong> từ <strong>" + order.StartTime.ToString() + "</trong> đến <strong>" + order.EndTime.ToString() + "</strong> đã bị chủ sân từ chối</p>"
                                  + "<p>Lí do: " + reason + "</p>"
                                  + "<p>Chúng tôi xin lỗi vì sự bất tiện này.</p>"
                                  + "<p>Hẹn gặp lại quý khách lần sau!</p>";

                        noti.Message = "Đơn đặt sân " + order.Field.Name + "(" + order.StartTime.ToString() + " - " + order.EndTime.ToString() + ") đã bị từ chối";
                    }
                    if (status == (int)OrderStatus.Cancel)
                    {
                        subject = "SSN - Đơn đặt sân đã bị hủy";
                        body    = "<p>Đơn đặt sân <strong>" + order.Field.Name + "</strong> từ <strong>" + order.StartTime.ToString() + "</trong> đến <strong>" + order.EndTime.ToString() + "</strong> đã bị chủ sân hủy</p>"
                                  + "<p>Lí do: " + reason + "</p>"
                                  + "<p>Chúng tôi xin lỗi vì sự bất tiện này.</p>"
                                  + "<p>Hẹn gặp lại quý khách lần sau!</p>";

                        noti.Message = "Đơn đặt sân " + order.Field.Name + "(" + order.StartTime.ToString() + " - " + order.EndTime.ToString() + ") đã bị hủy";
                    }

                    EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { receiverEmail, "*****@*****.**" }, null, null, subject, body, true);
                    _notificationService.Create(noti);
                    _notificationService.Save();


                    //Fire base noti
                    List <string> registrationIds = GetToken(noti.UserId);

                    //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                    NotificationModel Amodel = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(noti));

                    if (registrationIds != null && registrationIds.Count != 0)
                    {
                        Android.Notify(registrationIds, null, Amodel);
                    }

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);

                    return("success");
                }
            }
            else
            {
                return("false");
            }
        }
        public ActionResult Comment(int postId, String userId, String content, HttpPostedFileBase image)
        {
            var service = this.Service <IPostCommentService>();

            var notiService = this.Service <INotificationService>();

            var postService = this.Service <IPostService>();

            var aspNetUserService = this.Service <IAspNetUserService>();

            var likeService = this.Service <ILikeService>();

            ResponseModel <PostCommentDetailViewModel> response = null;

            try
            {
                String commentImage = null;

                if (image != null)
                {
                    FileUploader uploader = new FileUploader();

                    commentImage = uploader.UploadImage(image, userImagePath);
                }

                PostComment comment = service.Comment(postId, userId, content, commentImage);

                AspNetUser commentedUser = aspNetUserService.FindUser(comment.UserId);

                Post post = postService.GetPostById(comment.PostId);

                AspNetUser user = postService.GetUserNameOfPost(post.Id);

                List <string> AllRelativeUserIdOfPost = new List <string>();

                List <PostComment> listPostCmt = service.GetAllRelativeCmtDistinct(postId).ToList();

                List <Like> listPostLike = likeService.GetAllRelativeLikeDistinct(postId).ToList();

                foreach (var item in listPostCmt)
                {
                    AllRelativeUserIdOfPost.Add(item.UserId);
                }

                foreach (var item in listPostLike)
                {
                    AllRelativeUserIdOfPost.Add(item.UserId);
                }

                AllRelativeUserIdOfPost = AllRelativeUserIdOfPost.Distinct().ToList();

                //Noti to post creator
                if (!(post.UserId.Equals(commentedUser.Id)))
                {
                    string       u  = post.UserId;
                    string       u1 = commentedUser.Id;
                    Notification notiForPostCreator = notiService.SaveNoti(u, u1, "Comment", commentedUser.FullName + " đã bình luận về bài viết của bạn", int.Parse(NotificationType.Post.ToString("d")), post.Id, null, null);

                    //Fire base noti
                    List <string> registrationIds = GetToken(user.Id);

                    //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                    NotificationModel model = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(notiForPostCreator));

                    if (registrationIds != null && registrationIds.Count != 0)
                    {
                        Android.Notify(registrationIds, null, model);
                    }


                    //SignalR Noti
                    NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(notiForPostCreator));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
                }

                //noti to all user that relavtive in this post
                foreach (var item in AllRelativeUserIdOfPost)
                {
                    if (!(item.Equals(commentedUser.Id)) && !(item.Equals(post.UserId)))
                    {
                        string       i   = item;
                        string       i1  = commentedUser.Id;
                        Notification not = notiService.SaveNoti(item, commentedUser.Id, "Comment", commentedUser.FullName + " đã bình luận về bài viết mà bạn theo dõi", int.Parse(NotificationType.Post.ToString("d")), post.Id, null, null);

                        Notification noti = notiService.FirstOrDefaultActive(n => n.Id == not.Id);

                        //Fire base noti
                        List <string> registrationIds = GetToken(item);

                        //registrationIds.Add("dgizAK4sGBs:APA91bGtyQTwOiAgNHE_mIYCZhP0pIqLCUvDzuf29otcT214jdtN2e9D6iUPg3cbYvljKbbRJj5z7uaTLEn1WeUam3cnFqzU1E74AAZ7V82JUlvUbS77mM42xHZJ5DifojXEv3JPNEXQ");

                        NotificationModel model = Mapper.Map <NotificationModel>(PrepareNotificationCustomViewModel(noti));

                        if (registrationIds != null && registrationIds.Count != 0)
                        {
                            Android.Notify(registrationIds, null, model);
                        }


                        //SignalR Noti
                        NotificationFullInfoViewModel notiModelR = notiService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                        // Get the context for the Pusher hub
                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                        // Notify clients in the group
                        hubContext.Clients.User(notiModelR.UserId).send(notiModelR);
                    }
                }



                PostCommentDetailViewModel result = PreparePostCommentDetailViewModel(comment);

                response = new ResponseModel <PostCommentDetailViewModel>(true, "Bình luận thành công", null, result);
                post.LatestInteractionTime = DateTime.Now;
                postService.Update(post);
                postService.Save();
            }
            catch (Exception)
            {
                response = ResponseModel <PostCommentDetailViewModel> .CreateErrorResponse("Bình luận thất bại", systemError);
            }
            return(Json(response));
        }
        public ActionResult PostOnTimeLine(PostUploadViewModel model, string profileId)
        {
            var service = this.Service <IPostService>();

            var aspNetUserService = this.Service <IAspNetUserService>();

            var notiService = this.Service <INotificationService>();

            var memberService = this.Service <IGroupMemberService>();

            PostOveralViewModel result = null;

            ResponseModel <PostOveralViewModel> response = null;

            try
            {
                Post post = Mapper.Map <Post>(model);
                post.ProfileId = profileId;
                if (model.PostContent == null)
                {
                    post.PostContent = "";
                }
                post.ContentType = GetPostType(model);

                if (post.ContentType != int.Parse(ContentPostType.TextOnly.ToString("d")))
                {
                    FileUploader uploader = new FileUploader();

                    foreach (var img in model.UploadImage)
                    {
                        PostImage image = new PostImage();

                        image.Image = uploader.UploadImage(img, userImagePath);

                        post.PostImages.Add(image);
                    }
                }

                post = service.CreatePost(post);

                ////Notify all group members
                //if (post.GroupId != null)
                //{
                //    List<GroupMember> memberList = GetMemberList(post.GroupId);

                //    AspNetUser postedUser = aspNetUserService.FindUser(post.UserId);

                //    foreach (var member in memberList)
                //    {
                //        if (!(member.UserId.Equals(post.UserId)))
                //        {
                //            Notification noti = notiService.SaveNoti(member.UserId, post.UserId, "Post", postedUser.FullName + " đã đăng một bài viết", (int)NotificationType.Post, post.Id, null, null);

                //            List<string> registrationIds = GetToken(member.UserId);

                //            if (registrationIds != null && registrationIds.Count != 0)
                //            {
                //                NotificationModel notiModel = Mapper.Map<NotificationModel>(PrepareNotificationViewModel(noti));

                //                Android.Notify(registrationIds, null, notiModel);
                //            }
                //        }
                //    }
                //}

                if (post.UserId != profileId)
                {
                    var _notificationService = this.Service <INotificationService>();
                    var _userService         = this.Service <IAspNetUserService>();

                    AspNetUser sender = _userService.FindUser(post.UserId);

                    string title   = Utils.GetEnumDescription(NotificationType.Post);
                    int    type    = (int)NotificationType.Post;
                    string message = sender.FullName + " đã đăng một bài viết lên tường nhà bạn";

                    Notification noti = _notificationService.CreateNoti(profileId, post.UserId, title, message, type, post.Id, null, null, null);

                    //////////////////////////////////////////////
                    //signalR noti
                    NotificationFullInfoViewModel notiModel = _notificationService.PrepareNoti(Mapper.Map <NotificationFullInfoViewModel>(noti));

                    // Get the context for the Pusher hub
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <RealTimeHub>();

                    // Notify clients in the group
                    hubContext.Clients.User(notiModel.UserId).send(notiModel);
                }

                //Missing post sport

                result = Mapper.Map <PostOveralViewModel>(post);

                result.AspNetUser = Mapper.Map <AspNetUserSimpleModel>(aspNetUserService.FindUser(result.UserId));

                PreparePostOveralData(result, post.UserId);

                response = new ResponseModel <PostOveralViewModel>(true, "Đăng bài thành công!", null, result);
            }
            catch (Exception)
            {
                response = ResponseModel <PostOveralViewModel> .CreateErrorResponse("Đăng bài thất bại!", systemError);
            }

            return(Json(response));
        }