public BaseResponseAjaxModel Create(string email, string ip, string userAgent)
        {
            var responseData = new BaseResponseAjaxModel();

            bool emailAlreadyRegistered = this.newsletterRepos
                .All()
                .Where(n => n.Email == email)
                .Any();

            if (emailAlreadyRegistered)
            {
                responseData.ErrorMessage = string.Format("emai '{0}' is already registered for our newsletter.", email);
            }
            else
            {
                Newsletter dbNewsletter = new Newsletter()
                {
                    Email = email,
                    Ip = ip,
                    UserAgent = userAgent
                };

                this.newsletterRepos.Add(dbNewsletter);
                this.newsletterRepos.Save();

                responseData.Status = true;
            }

            return responseData;
        }
Ejemplo n.º 2
0
        public BaseResponseAjaxModel AddComment(string userId, string fromUserId, string commentText)
        {
            var response = new BaseResponseAjaxModel();

            if (commentText.Length < ModelConstants.CommentTextMinLength || commentText.Length > ModelConstants.CommentTextMaxLength)
            {
                response.ErrorMessage = string.Format("Comment text should be between {0} and {1} symbols long", ModelConstants.CommentTextMinLength, ModelConstants.CommentTextMaxLength);
                return response;
            }

            var dbUser = this.GetById(userId);

            if (dbUser == null)
            {
                response.ErrorMessage = "No such User";
                return response;
            }

            UserComment comment = new UserComment()
            {
                UserId = userId,
                AuthorId = fromUserId,
                Text = commentText
            };

            dbUser.Comments.Add(comment);
            this.userRepos.Save();
            this.userRepos.Reload(dbUser);

            var author = this.GetById(fromUserId);

            response.Status = true;
            response.Data = new CommentResponseModel()
            {
                FirstName = author.FirstName,
                LastName = author.LastName,
                UserUrl = ServicesDataProvider.GetProfileUrl(author.UserName, author.FirstName, author.LastName),
                UserImageSrc = ServicesDataProvider.GetUserImageSmallUrl(author.Avatar.FileName),
                CreatedOnFormatted = comment.CreatedOn.ToString("dd.MM.yyyy HH:mm"),
                CommentText = comment.Text,
                CommentTotalCount = dbUser.Comments.Count
            };

            return response;
        }
        public BaseResponseAjaxModel ApproveNotification(int notificationId, string userId)
        {
            var response = new BaseResponseAjaxModel();
            var notification = this.GetById(notificationId);

            if (notification == null)
            {
                response.ErrorMessage = "No such notification.";
                return response;
            }

            if (notification.ForUserId != userId)
            {
                response.ErrorMessage = "Only the owner of the notifcation can perfom this action";
                return response;
            }

            if (notification.ActionHasBeenTaken == true)
            {
                response.ErrorMessage = "Action for this notification has been already taken.";
                return response;
            }

            notification.ActionHasBeenTaken = true;

            if (notification.Type.Key == NotificationKey.JoinTripRequest)
            {
                return this.tripServices.ApproveJoinRequest(notification.TripId, notification.FromUser.UserName, userId);
            }

            if (notification.Type.Key == NotificationKey.FinishTripDriverRequest)
            {
                notification.Trip.Status = TripStatus.Finished;
                this.tripNotificationRepos.Save();
                response.Status = true;

                response.SignalRModel = this.tripServices.NotifyTripPassengersAndDriverForTripFinish(notification.Trip, userId);
                response.SignalRModel.RedirectToUrl = true;
                response.SignalRModel.UrlToRedirectTo = string.Format("/Trip/Rate/{0}/{1}-{2}", notification.TripId, notification.Trip.From.Name, notification.Trip.To.Name);
            }

            return response;
        }
Ejemplo n.º 4
0
        public BaseResponseAjaxModel LoadComments(string userId, int offset)
        {
            var dbUser = this.GetById(userId);
            var response = new BaseResponseAjaxModel();

            if (dbUser == null)
            {
                response.ErrorMessage = "No such User.";
                return response;
            }

            var comments = dbUser.Comments
                .Where(c => c.IsDeleted == false)
                .OrderByDescending(c => c.CreatedOn)
                .Skip(offset)
                .Take(WebApplicationConstants.CommentsOfset)
                .Select(c => new CommentResponseModel()
                {
                    FirstName = c.Author.FirstName,
                    LastName = c.Author.LastName,
                    UserUrl = ServicesDataProvider.GetProfileUrl(c.Author.UserName, c.Author.FirstName, c.Author.LastName),
                    UserImageSrc = ServicesDataProvider.GetUserImageSmallUrl(c.Author.Avatar.FileName),
                    CreatedOnFormatted = c.CreatedOn.ToString("dd.MM.yyyy HH:mm"),
                    CommentText = c.Text
                })
                .ToList();

            if (comments.Count() > 0)
            {
                int newOffset = offset + WebApplicationConstants.CommentsOfset;
                bool hasMoreCommentsToLoad = this.CheckIfTripHasMoreCommentsToLoad(dbUser.Id, newOffset);

                response.Status = true;
                response.Data = new LoadedCommentsResponseModel()
                {
                    HasMoreCommentsToLoad = hasMoreCommentsToLoad,
                    Offset = newOffset,
                    Comments = comments
                };
            }

            return response;
        }
        public BaseResponseAjaxModel DisapproveNotification(int notificationId, string userId)
        {
            var response = new BaseResponseAjaxModel();
            var notification = this.GetById(notificationId);

            if (notification == null)
            {
                response.ErrorMessage = "No such notification.";
                return response;
            }

            if (notification.ForUserId != userId)
            {
                response.ErrorMessage = "Only the owner of the notifcation can perfom this action";
                return response;
            }

            if (notification.ActionHasBeenTaken == true)
            {
                response.ErrorMessage = "Action for this notification has been already taken.";
                return response;
            }

            notification.ActionHasBeenTaken = true;

            if (notification.Type.Key == NotificationKey.JoinTripRequest)
            {
                return this.tripServices.DisapproveJoinRequest(notification.TripId, notification.FromUser.UserName, userId);
            }

            return response;
        }