示例#1
0
        public HttpResponseMessage Delete(Guid solutionCommentId)
        {
            try
            {
                var portal      = PortalController.GetCurrentPortalSettings();
                var currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

                if (currentUser.IsInRole("Registered Users"))
                {
                    SolutionCommentComponent solutionCommentComponent = new SolutionCommentComponent();
                    solutionCommentComponent = new SolutionCommentComponent(solutionCommentId);

                    if (solutionCommentComponent.Delete() > 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Accepted, "Successful Delete"));
                    }
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
            catch (HttpResponseException e)
            {
                throw e;
            }
            catch (Exception ee)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ee);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }
示例#2
0
        public List <SolutionCommentsModel> GetList(Guid solutionId, int rows = 10, int page = 0)
        {
            try
            {
                var portal      = PortalController.GetCurrentPortalSettings();
                var currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();


                var result     = SolutionCommentComponent.GetCommentsPerSolution(solutionId).OrderByDescending(p => p.CreatedDate).ToList();
                var totalCount = result.Count();
                var totalPages = (int)Math.Ceiling((double)totalCount / rows);


                var prevLink = page > 0 ? string.Format("/Comment/getlist?rows={0}&page={1}", rows, page - 1) : "";
                var nextLink = page < totalPages - 1 ? string.Format("/Comment/getlist?rows={0}&page={1}", rows, page + 1) : "";
                List <SolutionCommentsModel> SolutionCommentsModel = new List <SolutionCommentsModel>();

                foreach (var resultTmp in result.Skip(rows * page).Take(rows).ToList())
                {
                    var user = new UserPropertyComponent(resultTmp.UserId.GetValueOrDefault(-1));
                    SolutionCommentsModel.Add(new SolutionCommentsModel()
                    {
                        CommentId   = resultTmp.Comment_Id,
                        SolutionId  = (Guid)resultTmp.SolutionId,
                        UserId      = Convert.ToInt32(resultTmp.UserId),
                        FirstName   = user.UserProperty.FirstName,
                        LastName    = user.UserProperty.LastName,
                        Comment     = resultTmp.Comment,
                        CreatedDate = Convert.ToDateTime(resultTmp.CreatedDate),
                        Publish     = Convert.ToBoolean(resultTmp.Publish),
                        Scope       = resultTmp.Scope
                    });
                }

                var paginationHeader = new
                {
                    TotalCount   = totalCount,
                    TotalPages   = totalPages,
                    PrevPageLink = prevLink,
                    NextPageLink = nextLink
                };

                System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination",
                                                                    Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));

                return(SolutionCommentsModel);
            }
            catch (HttpResponseException e)
            {
                throw e;
            }
            catch (Exception ee)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ee);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }
示例#3
0
        public HttpResponseMessage CommentSolution(string txtComment, string scope, string solutionId)
        {
            try
            {
                var portalSettings = PortalController.GetCurrentPortalSettings();
                var currentUser    = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

                if (currentUser.IsInRole("Registered Users"))
                {
                    var solutionComponent = new SolutionComponent(new Guid(solutionId));

                    if (!string.IsNullOrEmpty(ValidateSecurity.ValidateString(txtComment, false)) && currentUser.UserID > 0 && solutionComponent.Solution.SolutionId != Guid.Empty)
                    {
                        SolutionCommentComponent solutionCommentComponent = new SolutionCommentComponent();
                        solutionCommentComponent.SolutionComment.Comment     = txtComment;
                        solutionCommentComponent.SolutionComment.CreatedDate = DateTime.Now;
                        solutionCommentComponent.SolutionComment.Publish     = true;
                        solutionCommentComponent.SolutionComment.Scope       = scope;
                        solutionCommentComponent.SolutionComment.SolutionId  = solutionComponent.Solution.SolutionId;
                        solutionCommentComponent.SolutionComment.UserId      = currentUser.UserID;

                        if (solutionCommentComponent.Save() > 0)
                        {
                            // Notification

                            var userToNotify        = DotNetNuke.Entities.Users.UserController.GetUserById(portalSettings.PortalId, Convert.ToInt32(solutionComponent.Solution.CreatedUserId));
                            var currentUserProperty = new UserPropertyComponent(currentUser.UserID);
                            if (currentUser.UserID != Convert.ToInt32(solutionComponent.Solution.CreatedUserId))
                            {
                                if (Helper.HelperMethods.SetNotification("COMMENT", "SOLUTION", solutionComponent.Solution.SolutionId, userToNotify.UserID, currentUser.UserID, "") > 0)
                                {
                                    Helper.HelperMethods.SendCommentNotificationEmails(solutionCommentComponent, portalSettings, currentUser);
                                    return(Request.CreateResponse(HttpStatusCode.OK, "Successful Operation"));
                                }
                            }
                        }

                        throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                    }

                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
            }
            catch (HttpResponseException e)
            {
                throw e;
            }
            catch (Exception ee)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ee);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }
示例#4
0
文件: Helper.cs 项目: OOcm1987/Nexso
        public static void SendCommentNotificationEmails(SolutionCommentComponent solutionCommentComponent, PortalSettings portalSettings, UserInfo currentUser)
        {
            ResourceManager Localization = new ResourceManager("NexsoServices.App_LocalResources.Resource",
                                                               Assembly.GetExecutingAssembly());
            List <int> userIds = new List <int>();

            foreach (SolutionComment solutionComment in solutionCommentComponent.SolutionComment.Solution.SolutionComments)
            {
                if (!userIds.Contains(solutionComment.UserId.GetValueOrDefault(-1)))
                {
                    userIds.Add(solutionComment.UserId.GetValueOrDefault(-1));
                }
            }
            if (solutionCommentComponent.SolutionComment.Solution.CreatedUserId.GetValueOrDefault(-1) != -1)
            {
                userIds.Add(solutionCommentComponent.SolutionComment.Solution.CreatedUserId.GetValueOrDefault(-1));
            }
            foreach (int userids in userIds)
            {
                UserInfo user = DotNetNuke.Entities.Users.UserController.GetUserById(portalSettings.PortalId, userids);
                UserPropertyComponent property = new UserPropertyComponent(userids);
                if (currentUser.UserID != user.UserID)
                {
                    CultureInfo language = new CultureInfo(HelperMethods.GetUserLanguage(property.UserProperty.Language.GetValueOrDefault(1)));
                    DotNetNuke.Services.Mail.Mail.SendEmail("*****@*****.**",
                                                            user.Email,
                                                            string.Format(
                                                                Localization.GetString("MessageTitleComment", language),
                                                                currentUser.FirstName + " " + currentUser.LastName,
                                                                solutionCommentComponent.SolutionComment.Solution.Title),
                                                            Localization.GetString("MessageBodyComment", language).Replace(
                                                                "{COMMENT:Body}", solutionCommentComponent.SolutionComment.Comment).Replace(
                                                                "{SOLUTION:Title}", solutionCommentComponent.SolutionComment.Solution.Title).Replace(
                                                                "{SOLUTION:PageLink}", NexsoHelper.GetCulturedUrlByTabName("solprofile", 7, language.Name) +
                                                                "/sl/" + solutionCommentComponent.SolutionComment.Solution.SolutionId.ToString())
                                                            );
                }
            }
            CultureInfo langua = new CultureInfo("en-US");

            DotNetNuke.Services.Mail.Mail.SendEmail("*****@*****.**",
                                                    "[email protected],[email protected], [email protected],[email protected],[email protected]", "NOTIFICATION: " +
                                                    string.Format(
                                                        Localization.GetString("MessageTitleComment", langua),
                                                        currentUser.FirstName + " " + currentUser.LastName, solutionCommentComponent.SolutionComment
                                                        .Solution.Title),
                                                    Localization.GetString("MessageBodyComment", langua).Replace(
                                                        "{COMMENT:Body}", solutionCommentComponent.SolutionComment.Comment).Replace(
                                                        "{SOLUTION:Title}", solutionCommentComponent.SolutionComment.Solution.Title).Replace(
                                                        "{SOLUTION:PageLink}", NexsoHelper.GetCulturedUrlByTabName("solprofile", 7, langua.Name) +
                                                        "/sl/" + solutionCommentComponent.SolutionComment.Solution.SolutionId.ToString())
                                                    );
        }