예제 #1
0
        public async Task <IActionResult> UpdateContentStatus(ContentApproveRequest contentApproveRequest)
        {
            try
            {
                QrcDataAccess _qrcAccess = new QrcDataAccess(_iconfiguration, _converter);

                DatabaseResponse response = await _qrcAccess.UpdateContentStatus(contentApproveRequest);

                if (response.ResponseCode == (int)DbReturnValue.RecordExists)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.RecordExists),
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    Log.Error(EnumExtensions.GetDescription(DbReturnValue.NotExists));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.NotExists),
                        ReturnedObject = response.Results
                    }));
                }
            }
            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    StatusCode = ((int)ResponseStatus.ServerError).ToString(),
                    IsDomainValidationErrors = false
                }));
            }
        }
예제 #2
0
        public async Task <DatabaseResponse> UpdateContentStatus(ContentApproveRequest contentApproveRequest)
        {
            try
            {
                SqlParameter[] parameters =
                {
                    new SqlParameter("@ContentApprovalId", SqlDbType.Int),
                    new SqlParameter("@ContentType",       SqlDbType.Int),
                    new SqlParameter("@Status",            SqlDbType.Int),
                    new SqlParameter("@Comment",           SqlDbType.NVarChar),
                    new SqlParameter("@CreatedBy",         SqlDbType.Int),
                    new SqlParameter("@ContentId",         SqlDbType.Int),
                    new SqlParameter("@EmailUrl",          SqlDbType.NVarChar)
                };

                parameters[0].Value = contentApproveRequest.ContentApprovalId;
                parameters[1].Value = contentApproveRequest.ContentType;
                parameters[2].Value = contentApproveRequest.Status;
                parameters[3].Value = contentApproveRequest.Comment;
                parameters[4].Value = contentApproveRequest.CreatedBy;
                parameters[5].Value = contentApproveRequest.ContentId;
                parameters[6].Value = contentApproveRequest.EmailUrl;
                _DataHelper         = new DataAccessHelper("spi_ContentApproval", parameters, _configuration);

                DataSet dt = new DataSet();

                int result = await _DataHelper.RunAsync(dt);

                UserEmail userEmail = null;
                if (dt.Tables[0] != null && dt.Tables[0].Rows.Count > 0 && dt.Tables[0].Rows.Count > 0)
                {
                    int    IsPublish        = Convert.ToInt32(dt.Tables[0].Rows[0]["PublishContent"]);
                    int    portalLanguageId = Convert.ToInt32(dt.Tables[0].Rows[0]["PortalLanguageId"]);
                    string text             = string.Empty;
                    string buttonText       = string.Empty;
                    if (IsPublish == 1)
                    {
                        //sent email for published
                        if (contentApproveRequest.ContentType == 1)
                        {
                            ContentMediaController controller = new ContentMediaController(_configuration, _converter);
                            await controller.GeneratePdf(contentApproveRequest.ContentId, 1);
                        }
                        else
                        {
                            ContentMediaController controller = new ContentMediaController(_configuration, _converter);
                            await controller.GeneratePdf(contentApproveRequest.ContentId, 2);
                        }
                        userEmail = new UserEmail();


                        userEmail.Email = Convert.ToString(dt.Tables[0].Rows[0]["Email"]);

                        if (portalLanguageId == 2)
                        {
                            text              = "Your Content  has been published. Click below button to view";
                            buttonText        = "View Content";
                            userEmail.Subject = "Your course or resource has been published.";
                        }
                        else
                        {
                            text              = "تم نشر المصدر المحتوى الخاص بك، يمكنك الضغط على الرابط أدناه للعرض";
                            buttonText        = "عرض المحتوى";
                            userEmail.Subject = "تم نشر المحتوى";
                        }
                        userEmail.Body = Emailer.CreateEmailBody(Convert.ToString(dt.Tables[0].Rows[0]["UserName"]),
                                                                 contentApproveRequest.EmailUrl, text, buttonText, dt.Tables[0].Rows[0]["PortalLanguageId"] == null?
                                                                 0: Convert.ToInt32(dt.Tables[0].Rows[0]["PortalLanguageId"]), _configuration);
                        await Emailer.SendEmailAsync(userEmail, _configuration);
                    }
                    else if (IsPublish == 0)
                    {
                        //sent email for published
                        userEmail       = new UserEmail();
                        userEmail.Email = Convert.ToString(dt.Tables[0].Rows[0]["Email"]);
                        if (portalLanguageId == 2)
                        {
                            if (dt.Tables[1] != null && dt.Tables[1].Rows.Count > 0)
                            {
                                text = "Your Content  has been rejected. Click below button to view. Reason(s) : ";
                                StringBuilder builder = new StringBuilder();
                                builder.Append("<br/>");
                                builder.Append("<ol>");
                                foreach (string reason in dt.Tables[1].Rows[0]["Comments"].ToString().Remove(dt.Tables[1].Rows[0]["Comments"].ToString().Length - 2).Split(";;"))
                                {
                                    builder.Append("<li>" + reason + "</li>");
                                }
                                builder.Append("</ol>");
                                text += builder.ToString();
                            }
                            else
                            {
                                text = "Your Content  has been rejected. Click below button to view. Reason : " + contentApproveRequest.Comment;
                            }

                            buttonText        = "View Content";
                            userEmail.Subject = "Your course or resource has been rejected.";
                        }
                        else
                        {
                            if (dt.Tables[1] != null && dt.Tables[1].Rows.Count > 0)
                            {
                                text = "بعد المراجعة، تم رفض المحتوى المقدم من قبلك خلال عملية التحقق من الجودة.يمكنك الضغط على الرابط أدناه لعرض المحتوى. " + "اللأسباب:";
                                StringBuilder builder = new StringBuilder();
                                builder.Append("<br/>");
                                builder.Append("<ol>");
                                foreach (string reason in dt.Tables[1].Rows[0]["Comments"].ToString().Remove(dt.Tables[1].Rows[0]["Comments"].ToString().Length - 2).Split(";;"))
                                {
                                    builder.Append("<li>" + reason + "</li>");
                                }
                                builder.Append("</ol>");
                                text += builder.ToString();
                            }
                            else
                            {
                                text = "بعد المراجعة، تم رفض المحتوى المقدم من قبلك خلال عملية التحقق من الجودة.يمكنك الضغط على الرابط أدناه لعرض المحتوى .<br><br>الأسباب:" + contentApproveRequest.Comment + "<br/>";
                            }

                            buttonText        = "عرض المحتوى";
                            userEmail.Subject = "تم رفض المحتوى.";
                        }
                        userEmail.Body = Emailer.CreateEmailBody(Convert.ToString(dt.Tables[0].Rows[0]["UserName"]), contentApproveRequest.EmailUrl, text, buttonText, dt.Tables[0].Rows[0]["PortalLanguageId"] == null ? 0 : Convert.ToInt32(dt.Tables[0].Rows[0]["PortalLanguageId"]), _configuration);
                        await Emailer.SendEmailAsync(userEmail, _configuration);
                    }
                }
                return(new DatabaseResponse {
                    ResponseCode = result, Results = null
                });
            }

            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                throw;
            }
            finally
            {
                _DataHelper.Dispose();
            }
        }