Пример #1
0
 public ActionResult NoticeDetails(int? idNotice)
 {
     NoticeDetailsViewModel ndvm = new NoticeDetailsViewModel();
     if (idNotice.HasValue)
     {
         List<NoticeComment> comments = new List<NoticeComment>();
         NoticeDetails nDet = new NoticeDetails();
         DBHelper.GetNoticeById(idNotice.Value, ref nDet, ref comments );
         ndvm.Notice = nDet;
         ndvm.NoticeComments = comments;
     }
     return View(ndvm);
 }
Пример #2
0
        public static void GetNoticeById(int idNotice, ref NoticeDetails nDet, ref List<NoticeComment> comments)
        {
            nDet = new NoticeDetails();

            using (eStanarContext context = new eStanarContext())
            {
                using (IDbConnection oaConnection = context.Database.Connection)
                {
                    oaConnection.Open();

                    using (IDbCommand oaCommand = oaConnection.CreateCommand())
                    {
                        oaCommand.CommandType = CommandType.StoredProcedure;
                        oaCommand.CommandText = "GetNoticeById";

                        SqlParameter idNoticeParameter = new SqlParameter()
                        {
                            ParameterName = "@idNoticeIn",
                            DbType = System.Data.DbType.Int32,
                            Direction = System.Data.ParameterDirection.Input,
                            Value = idNotice
                        };

                        oaCommand.Parameters.Add(idNoticeParameter);

                        var objectContext = ((IObjectContextAdapter)context).ObjectContext;

                        using (IDataReader dataReader = oaCommand.ExecuteReader())
                        {
                            nDet = objectContext.Translate<NoticeDetails>(dataReader as DbDataReader).ToList().First();

                            dataReader.NextResult();

                            comments = objectContext.Translate<NoticeComment>(dataReader as DbDataReader).ToList();
                        }
                    }
                }
            }
        }