Example #1
0
        public ActionResult CreateNewsComment(string userId, int newsId, string comment)
        {
            var _newsCommentService = this.Service <INewsCommentService>();
            var result = new AjaxOperationResult <NewsComment>();

            if (!String.IsNullOrEmpty(userId) && newsId != 0 && !String.IsNullOrEmpty(comment))
            {
                NewsComment nc = new NewsComment();
                nc.UserId     = userId;
                nc.NewsId     = newsId;
                nc.Comment    = comment;
                nc.CreateDate = DateTime.Now;
                _newsCommentService.Create(nc);
                _newsCommentService.Save();

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

            return(Json(result));
        }
Example #2
0
        public JsonResult Edit(NewsViewModel model, HttpPostedFileBase ImageFile)
        {
            var result = new AjaxOperationResult();

            if (ModelState.IsValid)
            {
                var service = this.Service <INewsService>();
                var news    = service.Get(q => q.Id == model.Id).SingleOrDefault();
                if (news != null)
                {
                    var uploader = new FileUploader();

                    if (ImageFile != null)
                    {
                        news.Image = uploader.UploadImage(ImageFile, userImagePath);
                    }
                    news.Title       = model.Title;
                    news.NewsContent = model.NewsContent;
                    news.CategoryId  = model.CategoryId;

                    service.Update(news);
                }
                else
                {
                    result.Succeed = false;
                }
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
Example #3
0
        public ActionResult LoadNewsComments(int id, int skip, int take)
        {
            var result = new AjaxOperationResult <List <NewsCommentDetailViewModel> >();

            if (id != 0)
            {
                var _newsCommentService = this.Service <INewsCommentService>();
                var _postService        = this.Service <IPostService>();


                List <NewsComment> newsComtList = _newsCommentService.GetNewsComments(id, skip, take).ToList();
                List <NewsCommentDetailViewModel> newsCmtListVM = Mapper.Map <List <NewsCommentDetailViewModel> >(newsComtList);
                foreach (var item in newsCmtListVM)
                {
                    item.CommentAge = _postService.CalculatePostAge(item.CreateDate);
                }

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

            return(Json(result));
        }
Example #4
0
        public ActionResult ApprovePlace(int id)
        {
            var result  = new AjaxOperationResult();
            var service = this.Service <IPlaceService>();
            var place   = service.Get(id);

            if (place == null)
            {
                return(this.IdNotFound());
            }
            else
            {
                try
                {
                    place.Approve = true;
                    place.Status  = (int)PlaceStatus.Active;
                    service.Update(place);
                    string subject = "[SSN] - Chấp nhận Sân";
                    string body    = "Hi <strong>" + place.AspNetUser.FullName + "</strong>" +
                                     "<br/><br>/Sân " + place.Name + " 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/> Tên sân : <strong>" + place.Name + "</strong>" +
                                     "<br/> số điện thoại : <strong>" + place.PhoneNumber + "</strong>" +
                                     "<br/> Địa chỉ : <strong>" + place.Address + " - " + place.Ward + " - " + place.District + " - " + place.City + "</strong>" +
                                     "<br/> Tên sân : <strong>" + place.Name + "</strong>";
                    EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { place.AspNetUser.Email }, null, null, subject, body, true);
                    result.Succeed = true;
                } catch (Exception)
                {
                    result.Succeed = false;
                }
            }

            return(Json(result));
        }
Example #5
0
        public ActionResult LoadGroupChat()
        {
            var result      = new AjaxOperationResult <List <InvitationViewModel> >();
            var userId      = User.Identity.GetUserId();
            var inviService = this.Service <IInvitationService>();
            var invitations = inviService.GetActive(p => (p.SenderId == userId || p.UserInvitations.Where(f => f.ReceiverId == userId && f.Accepted != false).ToList().Count > 0)).OrderByDescending(p => p.CreateDate).ToList();
            List <InvitationViewModel> rsList = new List <InvitationViewModel>();

            if (invitations != null)
            {
                foreach (var item in invitations)
                {
                    InvitationViewModel rs = Mapper.Map <InvitationViewModel>(item);
                    rs.Host = item.AspNetUser.FullName;
                    var tmp = item.UserInvitations.Where(p => p.Accepted != true).ToList().Count;
                    rs.numOfUser = item.UserInvitations.Count - tmp + 1;
                    rsList.Add(rs);
                }
                result.AdditionalData = rsList;
                result.Succeed        = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
Example #6
0
        public ActionResult getGroupPost(int groupId, string curUserId, int skip, int take)
        {
            var result = new AjaxOperationResult <IEnumerable <PostGeneralViewModel> >();

            if (groupId != 0)
            {
                var _postService        = this.Service <IPostService>();
                var _postCommentService = this.Service <IPostCommentService>();

                List <Post> postList = _postService.GetAllPostsOfGroup(groupId, skip, take).ToList();
                List <PostGeneralViewModel> listPostVM = Mapper.Map <List <PostGeneralViewModel> >(postList);

                foreach (var item in listPostVM)
                {
                    PrepareDetailPostData(item, curUserId);
                }

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

            return(Json(result));
        }
        public ActionResult DeletePost(int id)
        {
            var result       = new AjaxOperationResult();
            var _postService = this.Service <IPostService>();

            var _postImageService = this.Service <IPostImageService>();

            Post post = _postService.FirstOrDefaultActive(x => x.Id == id);

            if (post != null)
            {
                List <PostImage> imageList = _postImageService.GetActive(x => x.PostId == post.Id).ToList();

                if (imageList != null)
                {
                    for (int i = 0; i < imageList.Count; i++)
                    {
                        _postImageService.Delete(imageList[i]);
                    }
                }

                _postService.Deactivate(post);
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
        public ActionResult GetOrderBySport(int sportId)
        {
            var      result       = new AjaxOperationResult <List <OrderSimpleViewModel> >();
            var      userId       = User.Identity.GetUserId();
            var      placeService = this.Service <IPlaceService>();
            var      orderService = this.Service <IOrderService>();
            DateTime today        = DateTime.Now;
            var      orderList    = orderService.GetActive(p => p.Field.FieldType.SportId == sportId && p.UserId == userId &&
                                                           p.Status != (int)OrderStatus.Cancel && p.Status != (int)OrderStatus.Unapproved && p.StartTime > today).OrderByDescending(p => p.CreateDate).ToList();

            orderService.AutoCancelOrder(orderList);
            List <OrderSimpleViewModel> resultList = Mapper.Map <List <OrderSimpleViewModel> >(orderList);

            foreach (var item in resultList)
            {
                var place = placeService.FirstOrDefaultActive(p => p.Fields.Where(f => f.Id == item.FieldId).ToList().Count > 0);
                item.PlaceName       = place.Name;
                item.StartTimeString = item.StartTime.ToString("HH:mm");
                item.EndTimeString   = item.EndTime.ToString("HH:mm");
                item.PlayDateString  = item.StartTime.ToString("dd/MM/yyyy");
            }
            result.AdditionalData = resultList;
            result.Succeed        = true;
            return(Json(result));
        }
        /// <summary>
        /// 缺省的恢复操作
        /// </summary>
        /// <param name="context"></param>
        /// <param name="objName"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        protected string DefaultRestoreOperation(HttpContext context, string objName, Func <string, List <string>, bool> handler)
        {
            AjaxOperationResult aor = new AjaxOperationResult();

            try
            {
                string        restoreData = ReadHttpParameter(context, "restore_ids");
                List <string> ids         = JSON.ToObject <List <string> >(restoreData);

                // append operator information
                //  objName = objName + "$$" + CurrentUser.UserName;
                aor.success = handler(objName, ids);
            }
            catch
            {
                aor.success = false;
            }

            if (!aor.success)
            {
                aor.message = "还原失败";
            }

            return(JSON.ToJson(aor));
        }
Example #10
0
        public ActionResult CheckUsername(string username)
        {
            var result  = new AjaxOperationResult();
            var service = this.Service <IAspNetUserService>();

            if (username != null && username.Length > 0)
            {
                var user = service.GetActive(u => u.Email.ToLower().Equals(username.ToLower())).FirstOrDefault();
                if (user != null)
                {
                    result.Succeed = true;
                }
                else
                {
                    result.Succeed = false;
                    result.AddError("username", "Email không tồn tại trong hệ thống");
                }
            }
            else
            {
                result.Succeed = true;
            }

            return(Json(result));
        }
Example #11
0
        public ActionResult GetUserListInGroupChat(int invitationId)
        {
            var result          = new AjaxOperationResult <List <AspNetUserSimpleModel> >();
            var userService     = this.Service <IAspNetUserService>();
            var userInviService = this.Service <IUserInvitationService>();
            var inviService     = this.Service <IInvitationService>();
            List <AspNetUserSimpleModel> resultList = new List <AspNetUserSimpleModel>();
            var uIn = userInviService.GetActive(p => p.InvitationId == invitationId).ToList();

            if (uIn != null)
            {
                foreach (var item in uIn)
                {
                    var user = userService.FirstOrDefaultActive(p => p.Id == item.ReceiverId);
                    AspNetUserSimpleModel model = Mapper.Map <AspNetUserSimpleModel>(user);
                    resultList.Add(model);
                }
            }
            var invi    = inviService.FirstOrDefaultActive(p => p.Id == invitationId);
            var userId  = invi.SenderId;
            var curUser = userService.FirstOrDefaultActive(p => p.Id == userId);
            AspNetUserSimpleModel userModel = Mapper.Map <AspNetUserSimpleModel>(curUser);

            resultList.Add(userModel);
            result.AdditionalData = resultList;
            result.Succeed        = true;
            return(Json(result));
        }
Example #12
0
        public JsonResult CheckTimeValidInTimeBlock(int fieldId, string startTime, string endTime)
        {
            var      result            = new AjaxOperationResult();
            TimeSpan StartTime         = TimeSpan.Parse(startTime);
            TimeSpan EndTime           = TimeSpan.Parse(endTime);
            var      _timeBlockService = this.Service <ITimeBlockService>();

            try
            {
                bool rs = _timeBlockService.checkTimeValid(fieldId, StartTime, EndTime);
                if (rs)
                {
                    result.Succeed = true;
                }
                else
                {
                    result.Succeed = false;
                }
            }
            catch (Exception)
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
        public ActionResult Rating(int placeId, int score)
        {
            var result      = new AjaxOperationResult();
            var rateService = this.Service <IRatingService>();
            var userId      = User.Identity.GetUserId();
            var rate        = rateService.FirstOrDefaultActive(p => p.PlaceId == placeId && p.UserId == userId);

            if (rate != null)
            {
                rate.Point = score;
                rateService.Update(rate);
                rateService.Save();
            }
            else
            {
                Rating rating = new Rating();
                rating.PlaceId = placeId;
                rating.Point   = score;
                rating.UserId  = userId;
                rateService.Create(rating);
                rateService.Save();
            }
            result.Succeed = true;
            return(Json(result));
        }
Example #14
0
        public ActionResult UpdateNganLuongAccount(string userId, string accNL)
        {
            var _userService = this.Service <IAspNetUserService>();
            var result       = new AjaxOperationResult();

            AspNetUser user = _userService.FindUser(userId);

            if (user != null)
            {
                user.NganLuongAccount = accNL;
                if (_userService.UpdateUser(user) != null)
                {
                    result.Succeed = true;
                }
                else
                {
                    result.Succeed = false;
                }
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
Example #15
0
        public ActionResult CheckinOrder(string orderCode)
        {
            var result = new AjaxOperationResult();

            if (orderCode != null)
            {
                var   _orderService = this.Service <IOrderService>();
                Order order         = _orderService.FirstOrDefaultActive(o => o.OrderCode.Equals(orderCode));
                if (order != null)
                {
                    if (_orderService.ChangeOrderStatus(order.Id, (int)OrderStatus.CheckedIn) != null)
                    {
                        result.Succeed = true;
                    }
                    else
                    {
                        result.Succeed = false;
                        result.AddError("Update", "Đã có lỗi xảy ra");
                    }
                }
                else
                {
                    result.Succeed = false;
                    result.AddError("Update", "Không tìm thấy đơn đặt sân");
                }
            }
            else
            {
                result.Succeed = false;
                result.AddError("Update", "Đã có lỗi trong lúc truyền dữ liệu");
            }
            return(Json(result));
        }
        public ActionResult UnBanUser(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;
                    service.Update(user);
                    result.Succeed = true;
                }
                catch (Exception)
                {
                    result.Succeed = false;
                }
            }

            return(Json(result));
        }
        public ActionResult GetWard(string provinceName, string districtName)
        {
            var      result   = new AjaxOperationResult <IEnumerable <SelectListItem> >();
            Country  vietnam  = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH));
            Province province = vietnam.VietNamese.Where(p => p.Name.Equals(provinceName)).FirstOrDefault();
            IOrderedEnumerable <SelectListItem> wards = null;

            if (province != null)
            {
                District district = province.Districts
                                    .Where(d => d.Name.Equals(districtName))
                                    .FirstOrDefault();
                if (district != null)
                {
                    wards = district.Wards.Select(w =>
                                                  new SelectListItem
                    {
                        Text  = w.Type + " " + w.Name,
                        Value = w.Name
                    })
                            .OrderBy(w => w.Value);
                }
            }


            result.Succeed        = true;
            result.AdditionalData = wards;
            return(Json(result));
        }
        public ActionResult GetDistrict(string provinceName) //lam theo cai nay
        {
            var      result   = new AjaxOperationResult <IEnumerable <SelectListItem> >();
            Country  vietnam  = AddressUtil.GetINSTANCE().GetCountry(Server.MapPath(AddressUtil.PATH));
            Province province = vietnam.VietNamese.Where(p => p.Name.Equals(provinceName)).FirstOrDefault();
            IOrderedEnumerable <SelectListItem> districts = null;

            if (province != null)
            {
                //tao ra 1 mang select list item
                districts = province.Districts.Select(d =>
                                                      new SelectListItem
                {
                    Text  = d.Type + " " + d.Name,                     //hien len tren dropdown list
                    Value = d.Name                                     //value tra ve cho minh
                })
                            .OrderBy(d => d.Value);
            }

            result.Succeed        = true;
            result.AdditionalData = districts;


            return(Json(result));
        }
Example #19
0
        public ActionResult DeleteGroup(int groupId)
        {
            var result              = new AjaxOperationResult();
            var _groupService       = this.Service <IGroupService>();
            var _groupMemberService = this.Service <IGroupMemberService>();

            if (_groupService.DeleteGroup(groupId))
            {
                List <GroupMember> gmL = _groupMemberService.GetActive(g => g.GroupId == groupId).ToList();

                foreach (var item in gmL)
                {
                    if (_groupMemberService.LeaveGroup(groupId, item.UserId))
                    {
                        result.Succeed = true;
                    }
                }
                result.Succeed = true;
            }
            else
            {
                result.Succeed = false;
            }

            return(Json(result));
        }
Example #20
0
        public JsonResult CheckOrderTimeExist(int fieldId, string startTime, string endTime, string playDate)
        {
            var      result                = new AjaxOperationResult();
            TimeSpan StartTime             = TimeSpan.Parse(startTime);
            TimeSpan EndTime               = TimeSpan.Parse(endTime);
            DateTime PlayDate              = DateTime.ParseExact(playDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            var      _orderService         = this.Service <IOrderService>();
            var      _fieldScheduleService = this.Service <IFieldScheduleService>();

            try
            {
                bool rs1 = _orderService.checkTimeValidInOrder(fieldId, StartTime, EndTime, PlayDate, PlayDate);
                bool rs2 = _fieldScheduleService.checkTimeValidInFieldSchedule(null, fieldId, StartTime, EndTime, PlayDate, PlayDate);
                if (rs1 && rs2)
                {
                    result.Succeed = true;
                }
                else
                {
                    result.Succeed = false;
                }
            }
            catch (Exception)
            {
                result.Succeed = false;
            }
            return(Json(result));
        }
        public ActionResult getMoreCmtByPostId(int postId, int skip, int take)
        {
            var result = new AjaxOperationResult <IEnumerable <PostCommentDetailViewModel> >();
            var _postCommentService    = this.Service <IPostCommentService>();
            List <PostComment> cmtList = _postCommentService.GetCommentListByPostId(postId, skip, take).ToList();

            if (cmtList != null && cmtList.Count > 0)
            {
                List <PostCommentDetailViewModel> cmtListVM = Mapper.Map <List <PostCommentDetailViewModel> >(cmtList);
                foreach (var item in cmtListVM)
                {
                    //DateTime dt = DateTime.ParseExact(item.CreateDateString, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                    item.CommentAge = _postCommentService.CalculateCommentAge(item.CreateDate);
                }
                result.AdditionalData = cmtListVM;
                result.Succeed        = true;
            }
            else
            {
                result.Succeed = false;
            }


            return(Json(result));
        }
Example #22
0
        public ActionResult RejectPlace(int id)
        {
            var result  = new AjaxOperationResult();
            var service = this.Service <IPlaceService>();
            var place   = service.Get(id);

            if (place == null)
            {
                return(this.IdNotFound());
            }
            else
            {
                try
                {
                    place.Approve = false;
                    place.Status  = (int)PlaceStatus.Unapproved;
                    service.Update(place);
                    string subject = "[SSN] - Không Chấp nhận Sân";
                    string body    = "Hi <strong>" + place.AspNetUser.FullName + "</strong>" +
                                     "<br/><br>/Sân " + place.Name + " của bạn không được chấp nhận vì một số thông tin không hợp lệ" +
                                     "<br/> Tên sân : <strong>" + place.Name + "</strong>" +
                                     "<br/> số điện thoại : <strong>" + place.PhoneNumber + "</strong>" +
                                     "<br/> Địa chỉ : <strong>" + place.Address + " - " + place.Ward + " - " + place.District + " - " + place.City + "</strong>" +
                                     "<br/> Tên sân : <strong>" + place.Name + "</strong>";
                    EmailSender.Send(Setting.CREDENTIAL_EMAIL, new string[] { place.AspNetUser.Email }, null, null, subject, body, true);
                    result.Succeed = true;
                }
                catch (Exception)
                {
                    result.Succeed = false;
                }
            }
            return(Json(result));
        }
        public ActionResult GetSearchUserResult(string keyword, int skip, int take)
        {
            var result      = new AjaxOperationResult <ShowUserSearchViewModel>();
            var userService = this.Service <IAspNetUserService>();
            //var resultList = new List<AspNetUser>();
            //using (var db = new SSNEntities())
            //{
            //    resultList = userService.FindUserByName(db, keyword, 0, 5).ToList();
            //}
            var followService = this.Service <IFollowService>();
            var userCount     = userService.GetActive(p => p.AspNetRoles.Where(k =>
                                                                               k.Name != "Quản trị viên" && k.Name != "Moderator").ToList().Count > 0 && (p.FullName.Contains(keyword) || p.UserName.Contains(keyword) ||
                                                                                                                                                          p.Email.Contains(keyword))).OrderBy(p => p.FullName).ToList().Count;
            var resultList = userService.GetActive(p => p.AspNetRoles.Where(k =>
                                                                            k.Name != "Quản trị viên" && k.Name != "Moderator").ToList().Count > 0 && (p.FullName.Contains(keyword) || p.UserName.Contains(keyword) ||
                                                                                                                                                       p.Email.Contains(keyword))).OrderBy(p => p.FullName).Skip(skip).Take(take).ToList();
            var curUserId = User.Identity.GetUserId();
            var curUser   = userService.FirstOrDefaultActive(p => p.Id == curUserId);
            List <FollowSuggestViewModel> searchResultList = new List <FollowSuggestViewModel>();

            //List<FollowSuggestViewModel> searchResultList = Mapper.Map<List<FollowSuggestViewModel>>(ResultList);
            foreach (var user in resultList)
            {
                FollowSuggestViewModel model = Mapper.Map <FollowSuggestViewModel>(user);
                var hobbyCount = 1;
                foreach (var hobby in user.Hobbies.ToList())
                {
                    foreach (var curHobby in curUser.Hobbies)
                    {
                        if (hobby.SportId == curHobby.SportId)
                        {
                            model.sameSport = hobbyCount;
                            hobbyCount++;
                        }
                    }
                }
                var tmp = followService.GetActive(p => p.FollowerId == curUserId && p.UserId == user.Id).ToList().Count;
                if (tmp > 0)
                {
                    model.isFollowed = true;
                }
                else
                {
                    model.isFollowed = false;
                }
                searchResultList.Add(model);
            }
            ShowUserSearchViewModel searchResult = new ShowUserSearchViewModel();

            searchResult.userCount = userCount;
            searchResult.userList  = searchResultList;
            if (searchResultList.Count > 0)
            {
                result.AdditionalData = searchResult;
            }

            result.Succeed = true;
            return(Json(result));
        }
Example #24
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 GetFollowingUser(int skip, int take)
        {
            var result      = new AjaxOperationResult <List <FollowSuggestViewModel> >();
            var userService = this.Service <IAspNetUserService>();
            var userId      = User.Identity.GetUserId();
            var userList    = userService.GetActive(p => p.Follows.Where(f => f.FollowerId == userId && f.Active).ToList().Count > 0).OrderBy(p => p.FullName).Skip(skip).Take(take).ToList();
            List <FollowSuggestViewModel> suggestUserList = Mapper.Map <List <FollowSuggestViewModel> >(userList);

            result.AdditionalData = suggestUserList;
            result.Succeed        = true;
            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));
        }
Example #28
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));
        }
Example #29
0
        public JsonResult Delete(int id)
        {
            var result  = new AjaxOperationResult();
            var service = this.Service <INewsService>();
            var news    = service.Get(id);

            if (news != null)
            {
                news.Active = false;
                service.Update(news);
            }
            return(Json(result));
        }
Example #30
0
        public ActionResult CreateGroup(string GroupCreator, string GroupName, string GroupDescription, string GroupSport)
        {
            var result              = new AjaxOperationResult <GroupViewModel>();
            var _groupService       = this.Service <IGroupService>();
            var _groupMemberService = this.Service <IGroupMemberService>();

            if (!String.IsNullOrEmpty(GroupCreator) && !String.IsNullOrEmpty(GroupName) && !String.IsNullOrEmpty(GroupDescription) && !String.IsNullOrEmpty(GroupSport))
            {
                int _GroupSport = -1;
                if (int.TryParse(GroupSport, out _GroupSport) == false)
                {
                    result.Succeed = false;
                }
                Group group = new Group();
                group.Name        = GroupName;
                group.Description = GroupDescription;
                group.SportId     = _GroupSport;
                group.Avatar      = "/SSNImages/UserImages/img_default_avatar.png";
                group.CoverImage  = "/SSNImages/UserImages/img_default_cover.png";

                if (_groupService.CreateGroup(group) != null)
                {
                    GroupMember gm = new GroupMember();
                    gm.GroupId = group.Id;
                    gm.UserId  = GroupCreator;
                    gm.Admin   = true;
                    gm.Status  = (int)GroupMemberStatus.Approved; //mốt sửa khi có enum group status

                    if (_groupMemberService.CreateGroupMember(gm) != null)
                    {
                        GroupViewModel model = Mapper.Map <GroupViewModel>(group);
                        result.AdditionalData = model;
                        result.Succeed        = true;
                    }
                    else
                    {
                        result.Succeed = false;
                    }
                }
                else
                {
                    result.Succeed = false;
                }
            }
            else
            {
                result.Succeed = false;
            }
            return(Json(result));
        }