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));
        }
Esempio n. 2
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));
        }
        //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));
        }
Esempio n. 4
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));
        }
Esempio n. 5
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));
        }
Esempio n. 6
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");
            }
        }
Esempio n. 7
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));
        }
        public ActionResult Post(PostUploadViewModel model)
        {
            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 = post.UserId;
                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.GroupPost, post.Id, null, null);

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

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

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

                            // 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));
        }