Exemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(SystemNews model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SystemNews(");
            strSql.Append("NewsTitle,NewsContent,UserId,UserName,NewsStatus,NewsRealseTime");
            strSql.Append(") values (");
            strSql.Append("@NewsTitle,@NewsContent,@UserId,@UserName,@NewsStatus,@NewsRealseTime");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@NewsTitle",      SqlDbType.VarChar, 300),
                new SqlParameter("@NewsContent",    SqlDbType.VarChar,  -1),
                new SqlParameter("@UserId",         SqlDbType.Int,       4),
                new SqlParameter("@UserName",       SqlDbType.VarChar,  50),
                new SqlParameter("@NewsStatus",     SqlDbType.Int,       4),
                new SqlParameter("@NewsRealseTime", SqlDbType.DateTime)
            };

            parameters[0].Value = model.NewsTitle;
            parameters[1].Value = model.NewsContent;
            parameters[2].Value = model.UserId;
            parameters[3].Value = model.UserName;
            parameters[4].Value = model.NewsStatus;
            parameters[5].Value = model.NewsRealseTime; return(sqlhelper.ExecNon(strSql.ToString(), parameters));
        }
Exemplo n.º 2
0
        public JsonResult AddUpdateNews(SystemNews news)
        {
            //FormCollection form
            DataFornat dataformat = new DataFornat();

            JsonResult result = null;

            try
            {
                news.NewsContent = HttpUtility.UrlDecode(news.NewsContent);
                news.NewsContent = dataformat.ReplaceImageSrc(news.NewsContent, AppConfigHelper.MainSiteUrl);
                BaseResultDto <string> resultDto = new BaseResultDto <string>();
                //添加或者修改
                if (news.Id > 0)
                {
                    //修改
                    resultDto = HttpHelper.CreatHelper().DoPostObject <BaseResultDto <string> >(string.Format("{0}News/Update", this.WebApiUrl), news);
                }
                else
                {
                    news.NewsRealseTime = System.DateTime.Now;
                    news.UserName       = this.UserInfo.UserName;
                    news.UserId         = this.UserInfo.ID;
                    //添加
                    resultDto = HttpHelper.CreatHelper().DoPostObject <BaseResultDto <string> >(string.Format("{0}News/Add", this.WebApiUrl), news);
                }
                result = Json(new { status = resultDto.ErrorCode, message = resultDto.ErrorMsg }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                result = Json(new { status = -1, message = ex.Message }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SystemNews model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SystemNews set ");

            strSql.Append(" NewsTitle = @NewsTitle , ");
            strSql.Append(" NewsContent = @NewsContent , ");
            strSql.Append(" UserId = @UserId , ");
            strSql.Append(" UserName = @UserName , ");
            strSql.Append(" NewsStatus = @NewsStatus , ");
            strSql.Append(" NewsRealseTime = @NewsRealseTime  ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",             SqlDbType.Int,       4),
                new SqlParameter("@NewsTitle",      SqlDbType.VarChar, 300),
                new SqlParameter("@NewsContent",    SqlDbType.VarChar,  -1),
                new SqlParameter("@UserId",         SqlDbType.Int,       4),
                new SqlParameter("@UserName",       SqlDbType.VarChar,  50),
                new SqlParameter("@NewsStatus",     SqlDbType.Int,       4),
                new SqlParameter("@NewsRealseTime", SqlDbType.DateTime)
            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.NewsTitle;
            parameters[2].Value = model.NewsContent;
            parameters[3].Value = model.UserId;
            parameters[4].Value = model.UserName;
            parameters[5].Value = model.NewsStatus;
            parameters[6].Value = model.NewsRealseTime;
            return(sqlhelper.ExecNon(strSql.ToString(), parameters) > 0 ? true : false);
        }
Exemplo n.º 4
0
        public bool Update(SystemNews model, List <string> fileds, string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.AppendFormat("update {0} set ", model.GetType().Name);
            List <string>       filedsList   = new List <string>();
            List <SqlParameter> sqlParameter = new List <SqlParameter>();
            SqlParameter        Param        = new SqlParameter("@Id", SqlDbType.Int, 4);

            if (string.IsNullOrEmpty(sqlWhere))
            {
                Param.Value = model.Id;
                sqlParameter.Add(Param);
            }
            foreach (string filed in fileds)
            {
                filedsList.Add(string.Format("{0}=@{0}", filed));
                Param = new SqlParameter(string.Format("@{0}", filed), model.GetType().GetProperty(filed).GetValue(model, null));
                sqlParameter.Add(Param);
            }
            strSql.AppendFormat("{0}", string.Join(",", filedsList.ToArray()));
            if (string.IsNullOrEmpty(sqlWhere))
            {
                strSql.Append(" where Id=@Id ");
            }
            else
            {
                strSql.AppendFormat(" where 1=1 and {0} ", sqlWhere);
            }
            SqlParameter[] parameters = sqlParameter.ToArray();
            return(sqlhelper.ExecNon(strSql.ToString(), parameters) > 0 ? true : false);
        }
Exemplo n.º 5
0
        public void Persist(SystemNews item)
        {
            VtsWebServiceClient service = new VtsWebServiceClient();

            service.NewsPersist(SystemNewsAssembler.FromDomainObjectToDto(item));
            service.Close();
        }
Exemplo n.º 6
0
        public ActionResult Delete(int id)
        {
            NewsPersistency     persistency = new NewsPersistency();
            SystemNews          item        = persistency.Get(id);
            SystemNewsViewModel model       = new SystemNewsViewModel(item);

            return(View(model));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult AddNews(int Id)
        {
            SystemNews model = new SystemNews();

            if (Id > 0)
            {
                BaseResultDto <SystemNews> resultDto = HttpHelper.CreatHelper().DoGetObject <BaseResultDto <SystemNews> >(string.Format("{0}News/GetNews?Id={1}", this.WebApiUrl, Id));
                model = resultDto.Tag;
            }
            return(View(model));
        }
Exemplo n.º 8
0
        public SystemNewsViewModel(SystemNews model)
        {
            this.model      = model;
            Id              = model.Id;
            Date            = model.DatePublished;
            TopicEnglish    = model.GetTopic(0);
            TopicRussian    = model.GetTopic(1);
            TopicBelarusian = model.GetTopic(2);

            TextEnglish    = model.GetTopic(0);
            TextRussian    = model.GetTopic(1);
            TextBelarusian = model.GetTopic(2);
        }
Exemplo n.º 9
0
 public ActionResult Create(SystemNewsViewModel model)
 {
     try
     {
         SystemNews      item        = model.GetModel();
         NewsPersistency persistency = new NewsPersistency();
         persistency.Persist(item);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 10
0
        public static SystemNews FromDtoToDomainObject(SystemNewsDto source)
        {
            SystemNews target = new SystemNews();

            target.Id            = source.Id;
            target.DatePublished = source.DatePublished;
            target.IsBlocked     = source.IsBlocked;
            foreach (SystemNewsLocalizedDto newsLocalized in source.SystemNewsLocalized)
            {
                SystemNewsLocalized snld =
                    SystemNewsLocalizedAssembler.FromDtoToDomainObject(newsLocalized);
                target.SystemNewsLocalized.Add(snld);
            }
            return(target);
        }
Exemplo n.º 11
0
        public BaseResultDto <string> Update(SystemNews model)
        {
            BaseResultDto <string> resultDto = new BaseResultDto <string>();

            try
            {
                resultDto.ErrorCode = helper.Update <SystemNews>(model) ? 1 : 0;
                resultDto.ErrorMsg  = "修改成功";
            }
            catch (Exception ex)
            {
                resultDto.ErrorCode = -1;
                resultDto.ErrorMsg  = ex.Message;
            }
            return(resultDto);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 删除新闻
        /// </summary>
        /// <param name="news"></param>
        /// <returns></returns>
        public JsonResult DelNew(SystemNews news)
        {
            JsonResult result = null;

            try
            {
                //删除新闻
                BaseResultDto <string> resultDto = HttpHelper.CreatHelper().DoGetObject <BaseResultDto <string> >(string.Format("{0}News/Delete?Id={1}", this.WebApiUrl, news.Id));
                result = Json(new { status = resultDto.ErrorCode, message = resultDto.ErrorMsg }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                result = Json(new { status = -1, message = ex.Message }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }
Exemplo n.º 13
0
        public BaseResultDto <string> Add(SystemNews model)
        {
            BaseResultDto <string> resultDto = new BaseResultDto <string>();

            try
            {
                resultDto.ErrorCode = helper.Add <SystemNews>(model);
                resultDto.ErrorMsg  = "添加成功";
            }
            catch (Exception ex)
            {
                resultDto.ErrorCode = -1;
                resultDto.ErrorMsg  = ex.Message;
            }
            return(resultDto);
        }
Exemplo n.º 14
0
        public static SystemNewsDto FromDomainObjectToDto(SystemNews source)
        {
            SystemNewsDto target = new SystemNewsDto();

            target.Id            = source.Id;
            target.DatePublished = source.DatePublished;
            target.IsBlocked     = source.IsBlocked;
            IList <SystemNewsLocalizedDto> list = new List <SystemNewsLocalizedDto>();

            foreach (SystemNewsLocalized newsLocalized in source.SystemNewsLocalized)
            {
                SystemNewsLocalizedDto snld =
                    SystemNewsLocalizedAssembler.FromDomainObjectToDto(newsLocalized);
                list.Add(snld);
            }
            target.SystemNewsLocalized = list.ToArray();
            return(target);
        }
Exemplo n.º 15
0
        public ActionResult Create(NewsEntryViewModel newsEntry)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new NewsEntryViewModel
                {
                    SystemNews = newsEntry.SystemNews
                };
                return(View("NewsEntry", viewModel));
            }
            SystemNews systemNews = new SystemNews()
            {
                EnteredDateTime = DateTime.Now,
                Entry           = newsEntry.SystemNews.Entry
            };

            _context.SystemNews.Add(systemNews);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 16
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SystemNews GetModel(string where)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id, NewsTitle, NewsContent, UserId, UserName, NewsStatus, NewsRealseTime  ");
            strSql.Append("  from SystemNews ");
            strSql.Append(" where ");
            strSql.Append(where);



            var        dt    = sqlhelper.GetTable(strSql.ToString());
            SystemNews model = null;

            if (dt.Rows.Count > 0)
            {
                model = Mapper.DynamicMap <IDataReader, List <SystemNews> >(dt.CreateDataReader()).FirstOrDefault();
            }
            return(model);
        }
Exemplo n.º 17
0
 public SystemNewsViewModel()
 {
     Date  = DateTime.Now;
     model = new SystemNews();
 }