Ejemplo n.º 1
0
        public bool UpdateAlert(AlertModel alertModel)
        {
            int rowseffected = 0;

            try
            {
                SqlParameter[] parameters =
                {
                    new SqlParameter("@alertId", alertModel.AlertId)
                    ,                            new SqlParameter("@alertTitle", alertModel.AlertTitle)
                    ,                            new SqlParameter("@alertDate", _sql.ConvertDateTimeForSQL(alertModel.AlertDate))
                    ,                            new SqlParameter("@alertDateEnd", _sql.ConvertDateTimeForSQL(alertModel.AlertDateEnd))
                    ,                            new SqlParameter("@alertShortDetails", alertModel.AlertShortDetails)
                    ,                            new SqlParameter("@alertLongDetails", alertModel.AlertLongDetails)
                    ,                            new SqlParameter("@alertImageLocation", alertModel.AlertImageLocation)
                };
                rowseffected = _sql.GetReturnValueFromStoredProcedure("UpdateAlert", parameters);
            }
            catch (Exception ex)
            {
                string error = string.Format(
                    "There was an error updating Alert #{0} into database AlertService/UpdateAlert",
                    alertModel.AlertId);
                _logger.LogError(error, ex);
            }

            return(rowseffected > 0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds an article to the database
        /// </summary>
        /// <param name="article"></param>
        /// <returns>The Id of the Article which was added</returns>
        public int AddArticleToNewsletter(int newsletterId)
        {
            string currentUser   = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
            int    currentUserId = -1;

            if (string.IsNullOrEmpty(currentUser))
            {
                _logger.LogError("CurrentUserId was unable to be acquired in ArticleService/AddArticle", null);
            }
            else
            {
                currentUserId = string.IsNullOrEmpty(currentUser) ? -1 : Int32.Parse(currentUser);
            }

            int returnedArticleId = 0;

            try
            {
                SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@newsletterId", newsletterId),
                    new SqlParameter("@addedBy", currentUserId),
                    new SqlParameter("@dateAdded", _sql.ConvertDateTimeForSQL(DateTime.Now)),
                    new SqlParameter("@articleId", returnedArticleId)
                };

                returnedArticleId = _sql.GetReturnValueFromStoredProcedure("AddArticle", parameters);
            }
            catch (Exception ex)
            {
                _logger.LogError("There was an error Adding/Inserting the article model in the Article Service", ex);
            }

            return(returnedArticleId);
        }
Ejemplo n.º 3
0
        private bool EnterImageIntoDatabase(ArticleImageModel image)
        {
            int rowseffected = 0;

            try
            {
                SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@uploadedByUserId", image.UploadedByUserId),
                    new SqlParameter("@uploadedByUserName", image.UploadedByUserName),
                    new SqlParameter("@uploadedDate", _sql.ConvertDateTimeForSQL(DateTime.Now)),
                    new SqlParameter("@simpleCheckSum", image.SimpleCheckSum),
                    new SqlParameter("@imageName", image.ImageName),
                    new SqlParameter("@imageLocation", image.ImageLocation)
                };

                rowseffected = _sql.GetReturnValueFromStoredProcedure("AddImageToArticleImages", parameters);
            }
            catch (Exception ex)
            {
                string error = string.Format(
                    "There was an error entering {0} into database ArticleImageService/EnterImageIntoDatabase",
                    image.ImageName);
                _logger.LogError(error, ex);
            }
            return(rowseffected > 0);
        }
Ejemplo n.º 4
0
        public IEnumerable <EventModel> GetEventsForDay(DateTime day)
        {
            List <EventModel> events = new List <EventModel>();

            try
            {
                SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@day", _sql.ConvertDateTimeForSQL(day))
                };

                DataSet eventsDataSet = _sql.GetDatasetFromStoredProcedure("GetEventsForDay", parameters);

                IEnumerable <DataRow> eventResults = eventsDataSet.Tables[0].AsEnumerable();

                foreach (var eventResult in eventResults)
                {
                    EventModel eventModel = new EventModel(eventResult);
                    events.Add(eventModel);
                }
            }
            catch (Exception ex)
            {
                string error = string.Format(
                    "There was an retrieving events for {0} in EventService/GetEventsForDay",
                    day.ToString());
                _logger.LogError(error, ex);
            }
            return(events.AsEnumerable());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a newsletter to the database along with all it's articles
        /// </summary>
        /// <param name="newsletter"></param>
        /// <returns>true if newsletter was added successfully</returns>
        public int AddNewsletter()
        {
            NewsletterModel newsletter = new NewsletterModel();

            string currentUser   = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
            int    currentUserId = -1;

            if (string.IsNullOrEmpty(currentUser))
            {
                _logger.LogError("CurrentUserId was unable to be acquired in NewsletterService/AddNewsletter", null);
            }
            else
            {
                currentUserId = string.IsNullOrEmpty(currentUser) ? -1 : Int32.Parse(currentUser);
            }

            int returnedNewsletterId = -1;

            try
            {
                SqlParameter[] parameters = new SqlParameter[]
                {
                    new SqlParameter("@createdDate", _sql.ConvertDateTimeForSQL(DateTime.Now)),
                    new SqlParameter("@createdBy", currentUserId),
                    new SqlParameter("@memo", "Please Update"),
                    new SqlParameter("@displayDate", DateTime.Now.ToString("yyyy-MM")),
                    new SqlParameter("@newsletterId", returnedNewsletterId)
                };

                returnedNewsletterId = _sql.GetReturnValueFromStoredProcedure("AddNewsletter", parameters);
            }
            catch (Exception ex)
            {
                _logger.LogError("There was an error Adding/Inserting the newsletter model in the Newsletter Service", ex);
            }

            return(returnedNewsletterId);
        }