Example #1
0
        public async Task <DatabaseResponse> UpdateContentStatus(MoEContentStatus contentUpdate)
        {
            try
            {
                SqlParameter[] parameters =
                {
                    new SqlParameter("@UserId",      SqlDbType.Int),
                    new SqlParameter("@ContentId",   SqlDbType.Int),
                    new SqlParameter("@ContentType", SqlDbType.Int),
                    new SqlParameter("@Status",      SqlDbType.Bit),
                    new SqlParameter("@Comments",    SqlDbType.NVarChar),
                    new SqlParameter("@EmailUrl",    SqlDbType.NVarChar)
                };

                parameters[0].Value = contentUpdate.UserId;
                parameters[1].Value = contentUpdate.ContentId;
                parameters[2].Value = contentUpdate.ContentType;
                parameters[3].Value = contentUpdate.Status;
                parameters[4].Value = contentUpdate.comments;
                parameters[5].Value = contentUpdate.EmailUrl;

                _DataHelper = new DataAccessHelper("spi_MoEApproveReject", parameters, _configuration);

                DataTable dt     = new DataTable();
                int       result = await _DataHelper.RunAsync(dt);

                if (dt.Rows.Count > 0)
                {
                    int    portalLanguageId = Convert.ToInt32(dt.Rows[0]["PortalLanguageId"]);
                    string text             = string.Empty;
                    string buttonText       = string.Empty;
                    if (result == (int)DbReturnValue.Published)
                    {
                        if (contentUpdate.ContentType == 1)
                        {
                            ContentMediaController controller = new ContentMediaController(_configuration, _converter);
                            await controller.GeneratePdf(contentUpdate.ContentId, 1);
                        }
                        else
                        {
                            ContentMediaController controller = new ContentMediaController(_configuration, _converter);
                            await controller.GeneratePdf(contentUpdate.ContentId, 2);
                        }
                        UserEmail userEmail = new UserEmail();

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

                        if (portalLanguageId == 2)
                        {
                            text = "Your Content has been published during expert check.";
                            userEmail.Subject = "Content has been published";
                            buttonText        = "View Content";
                        }
                        else
                        {
                            text = "تم نشر المصدر المحتوى الخاص بك، يمكنك الضغط على الرابط أدناه للعرض.";
                            userEmail.Subject = "تم نشر المحتوى .";
                            buttonText        = "عرض المحتوى";
                        }
                        userEmail.Body = Emailer.CreateEmailBody(Convert.ToString(dt.Rows[0]["UserName"]), contentUpdate.EmailUrl, text, buttonText, dt.Rows[0]["PortalLanguageId"] == null ? 0 : Convert.ToInt32(dt.Rows[0]["PortalLanguageId"]), _configuration);

                        await Emailer.SendEmailAsync(userEmail, _configuration);
                    }
                    else if (result == (int)DbReturnValue.Rejected)
                    {
                        UserEmail userEmail = new UserEmail();
                        userEmail.Email = Convert.ToString(dt.Rows[0]["Email"]);
                        if (portalLanguageId == 2)
                        {
                            text              = "Your Content has been rejected during expert check. Click below button to view. <br/> Reason : " + contentUpdate.comments;
                            buttonText        = "View Content";
                            userEmail.Subject = "Content has been rejected";
                        }
                        else
                        {
                            text              = "بعد المراجعة، تم رفض المحتوى المقدم من قبلك. يمكنك الضغط على الرابط أدناه لعرض المحتوى.<br><br>الأسباب:" + contentUpdate.comments + "<br/>";
                            buttonText        = "عرض المحتوى";
                            userEmail.Subject = "بعد المراجعة، تم رفض المحتوى المقدم من قبلك.";
                        }
                        userEmail.Body = Emailer.CreateEmailBody(Convert.ToString(dt.Rows[0]["UserName"]), contentUpdate.EmailUrl, text, buttonText, dt.Rows[0]["PortalLanguageId"] == null ? 0 : Convert.ToInt32(dt.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();
            }
        }
Example #2
0
        public async Task <IActionResult> UpdateContentStatus(MoEContentStatus contentUpdate)
        {
            try
            {
                MoECheckDataAccess moeCheckDataAccess = new MoECheckDataAccess(_configuration, _converter);

                DatabaseResponse response = await moeCheckDataAccess.UpdateContentStatus(contentUpdate);

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

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

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.ReviewedByOtherUsers),
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.ActionAlreadyTaken),
                        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
                }));
            }
        }