Ejemplo n.º 1
0
        public void DeleteNews(News news)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var newsEntity = from item in context.News
                                 where item.NewsID == news.NewsID
                                 select item;

                News entity = newsEntity.SingleOrDefault();

                if (entity != null)
                {
                    context.DeleteObject(entity);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Entities.News entity = new Entities.News();
            try
            {
                entity.NewsID = base.GetInt32("ID");
                entity.Title = txtNewsTitle.Text;
                entity.Text = txtNewsText.Text;

                entity.IsEnabled = chkUserIsEnabled.Checked;

                switch (base.Operation)
                {
                    case "I":
                        entity = SaveFile();
                        if (entity != null)
                        {
                            entity.Title = txtNewsTitle.Text;
                            entity.Text = txtNewsText.Text;
                            entity.IsEnabled = chkUserIsEnabled.Checked;

                            ServiceFactory.CreateConfigurationService.InsertNews(entity);
                        }

                        break;
                    case "U":
                        ServiceFactory.CreateConfigurationService.UpdateNews(entity);
                        break;
                    case "D":
                        ServiceFactory.CreateConfigurationService.DeleteNews(entity);
                        break;
                }
                Response.Redirect("NewsList.aspx", false);
            }
            catch
            {
                base.SetMessage(lblMessage, MessageType.Error, ResourceMessages.UnexpectedErrorMessage);
            }
        }
Ejemplo n.º 3
0
        public Entities.News SaveFile()
        {
            if (FileUploadControl.HasFile)
            {
                Entities.News result = new Entities.News();
                string extension = Path.GetExtension(FileUploadControl.FileName);
                string filename = Path.GetFileName(FileUploadControl.FileName);
                string aux = filename.Replace(extension, "");

                try
                {
                    string saveName = aux + DateTime.Now.ToString("_ddMMyyyy") + extension;
                    FileUploadControl.SaveAs(Server.MapPath(Param.NewsDocumentLibrary) + saveName);
                    result.FilePath = Param.NewsDocumentLibrary + saveName;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return result;
            }
            return null;
        }
Ejemplo n.º 4
0
        public void UpdateNews(News news)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var newsList = from item in context.News
                               where item.NewsID == news.NewsID
                               select item;

                News entity = newsList.SingleOrDefault();

                if (entity != null)
                {
                    entity.Title = news.Title;
                    entity.Text = news.Text;
                    entity.IsEnabled = news.IsEnabled;

                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 5
0
 public void InsertNews(News news)
 {
     using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
     {
         news.CreateDate = DateTime.Now;
         context.AddToNews(news);
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Create a new News object.
 /// </summary>
 /// <param name="newsID">Initial value of the NewsID property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="filePath">Initial value of the FilePath property.</param>
 /// <param name="createDate">Initial value of the CreateDate property.</param>
 /// <param name="isEnabled">Initial value of the IsEnabled property.</param>
 public static News CreateNews(global::System.Int32 newsID, global::System.String title, global::System.String text, global::System.String filePath, global::System.DateTime createDate, global::System.Boolean isEnabled)
 {
     News news = new News();
     news.NewsID = newsID;
     news.Title = title;
     news.Text = text;
     news.FilePath = filePath;
     news.CreateDate = createDate;
     news.IsEnabled = isEnabled;
     return news;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the News EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToNews(News news)
 {
     base.AddObject("News", news);
 }