コード例 #1
0
        public JsonResult GetCommentsByUser(string key, string username)
        {
            if (apiServices.IsValidKey(key))
            {
                UserProfileModel userProfileModel = accountServices.GetUserProfileByUsername(username);
                List<CommentModel> comments = commentServices.GetAllCommentsByUserProfileId(userProfileModel.UserProfileId).ToList();

                CommentViewModel[] result = new CommentViewModel[comments.Count];
                CommentViewModel cvm;

                for (int i = 0; i < comments.Count; i++)
                {
                    cvm = new CommentViewModel();
                    cvm.CommentId = comments[i].CommentId;
                    cvm.EventId = comments[i].EventId;
                    cvm.UserProfileId = comments[i].UserProfileId;
                    cvm.CommentText = comments[i].CommentText;
                    cvm.Timestamp = comments[i].Timestamp;
                    result[i] = cvm;
                }

                apiServices.IncrementKeyUsage(key);

                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }
コード例 #2
0
        public ActionResult Index(int id = 0)
        {
            EventModel model = eventServices.GetEventById(id);
            if (model == null) return RedirectToAction("Index", "Home");

            IEnumerable<MediaItemModel> medias = MediaServices.GetInstance().GetMediaItemsByEvent(model.EventId);
            List<String> mediasFilesnames = new List<String>();

            foreach (MediaItemModel mim in medias)
            {
                //mediasFilesnames.Add(HttpContext.Server.MapPath("~/Uploads/Images/" + mim.FileName));
                mediasFilesnames.Add(mim.FileName);
            }

            EventCommentViewModel ecvm = new EventCommentViewModel
            {
                Address = model.Location.Address,
                Latitude = model.Location.Latitude,
                Longitude = model.Location.Longitude,
                EventId = model.EventId,
                StartTime = model.StartTime,
                EndTime = model.EndTime,
                Title = model.Title,
                Description = model.Description,
                Created = model.Created,
                CreatedById = model.CreatedById,
                IsActive = model.IsActive,
                IsPrivate = model.IsPrivate,
                LastModified = model.LastModified,
                Rating = model.Rating,
                NewComment = "",
                MediaFileNameList = mediasFilesnames.AsEnumerable(),
                CategoryString = model.Category.Name,
                CreatorUsername = accountServices.GetUserByUserProfileId(model.CreatedById).Username
            };

            ecvm.CreatedByUser = false;
            UserProfileModel profile = accountServices.GetUserProfileByUsername(User.Identity.Name);
            if (profile != null)
            {
                if (ecvm.CreatedById == profile.UserProfileId)
                {
                    ecvm.CreatedByUser = true;
                }
            }

            IEnumerable<CommentModel> tempie = commentServices.GetAllCommentsByEventId(model.EventId);
            List<CommentViewModel> commentList = new List<CommentViewModel>();

            DateTime now = DateTime.Now;

            int userProfileId = accountServices.GetUserByUsername(User.Identity.Name).UserProfile.UserProfileId;

            foreach (CommentModel cm in tempie)
            {
                UserProfileModel upm = accountServices.GetUserProfileByUserProfileId(cm.UserProfileId);

                CommentViewModel cvm = new CommentViewModel
                {
                    CommenterName = upm.FirstName + " " + upm.LastName,
                    CommentId = cm.CommentId,
                    CommentText = cm.CommentText,
                    EventId = cm.EventId,
                    Timestamp = cm.Timestamp,
                    UserProfileId = cm.UserProfileId,
                    UserIsAuthor = cm.UserProfileId == userProfileId
                };

                if (now.Month == cm.Timestamp.Month)
                {
                    if (now.Day == cm.Timestamp.Day)
                    {
                        int mins;
                        if (now.Hour == cm.Timestamp.Hour)
                        {
                            mins = (now.Minute - cm.Timestamp.Minute);
                        }
                        else if (now.Hour == cm.Timestamp.Hour + 1 && (now.Minute + 60 - cm.Timestamp.Minute) < 60)
                        {
                            mins = (now.Minute + 60 - cm.Timestamp.Minute);
                        }
                        else
                        {
                            mins = -1;
                        }

                        if (mins == 0)
                        {
                            cvm.TimeString = "Just now";
                        }
                        else if (mins == 1)
                        {
                            cvm.TimeString = "1 minute ago";
                        }
                        else if (mins == -1)
                        {
                            cvm.TimeString = cm.Timestamp.ToShortTimeString();
                        }
                        else
                        {
                            cvm.TimeString = mins + " minutes ago";
                        }

                    }
                    else
                    {
                        cvm.TimeString = cm.Timestamp.ToShortDateString();
                    }
                }
                else
                {
                    cvm.TimeString = cm.Timestamp.ToShortDateString();
                }

                commentList.Add(cvm);
            }

            ecvm.CommentList = commentList;

            return View(ecvm);
        }