コード例 #1
0
        public virtual ActionResult JournalClear(int?IdJournal = null)
        {
            var answer = JsonAnswer();

            try
            {
                if (!IdJournal.HasValue)
                {
                    throw new Exception("Не указан идентификатор журнала.");
                }

                var result = AppCore.Get <JournalingManager>().GetJournal(IdJournal.Value);
                if (!result.IsSuccess)
                {
                    throw new Exception(result.Message);
                }

                using (var db = new JournalingDB.DataContext())
                    using (var scope = db.CreateScope())
                    {
                        db.DataContext.ExecuteQuery("DELETE FROM Journal WHERE IdJournal=@IdJournal", new { IdJournal = result.Result.IdJournal });
                        scope.Commit();
                    }
                answer.FromSuccess(null);
            }
            catch (Exception ex)
            {
                this.RegisterEventWithCode(System.Net.HttpStatusCode.InternalServerError, "Ошибка во время удаления журнала", $"Журнал №{IdJournal}", ex);
                answer.FromFail("Ошибка во время удаления журнала.");
            }
            return(ReturnJson(answer));
        }
コード例 #2
0
        public virtual ActionResult Journals()
        {
            using (var db = new JournalingDB.DataContext())
            {
                var dbAccessor = AppCore.Get <JournalingDB.JournalingManagerDatabaseAccessor <WebApplication> >();

                var queryDataBase    = dbAccessor.CreateQueryJournalData(db);
                var queryDataGrouped = from row in queryDataBase
                                       group row.JournalData by row.JournalName.IdJournal into gr
                                       select new { Count = gr.Count(), IdJournalDataLast = gr.Max(x => x.IdJournalData) };

                var query = from row in queryDataBase
                            join sq2 in queryDataGrouped on row.JournalData.IdJournalData equals sq2.IdJournalDataLast
                            select new Model.JournalQueries.QueryJournalData
                {
                    JournalData = row.JournalData,
                    JournalName = row.JournalName,
                    User        = row.User,
                    Count       = sq2.Count
                };

                var data = dbAccessor.
                           FetchQueryJournalData <Model.JournalQueries.QueryJournalData, Model.JournalQueries.JournalData>(query, (row, instance) => instance.Count = row.Count).
                           Select(x => new Design.Model.JournalsList()
                {
                    JournalName   = x.JournalInfo,
                    EventsCount   = x.Count,
                    EventLastDate = x.DateEvent,
                    EventLastType = x.EventType
                }).ToList();

                return(View("Journals.cshtml", data));
            }
        }
コード例 #3
0
        public virtual ActionResult JournalDetails(int?IdJournal = null)
        {
            try
            {
                if (!IdJournal.HasValue)
                {
                    throw new Exception("Не указан идентификатор журнала.");
                }

                using (var scope = TransactionsHelper.ReadUncommited())
                {
                    var result = AppCore.Get <JournalingManager>().GetJournal(IdJournal.Value);
                    if (!result.IsSuccess)
                    {
                        throw new Exception(result.Message);
                    }

                    var dbAccessor = AppCore.Get <JournalingDB.JournalingManagerDatabaseAccessor <WebApplication> >();

                    using (var db = new JournalingDB.DataContext())
                    {
                        int skip  = 0;
                        int limit = 100;

                        var query = dbAccessor.CreateQueryJournalData(db).Where(x => x.JournalData.IdJournal == result.Result.IdJournal).OrderByDescending(x => x.JournalData.DateEvent).Skip(skip).Take(limit);
                        var data  = dbAccessor.FetchQueryJournalData(query);
                        return(View("JournalDetails.cshtml", new Design.Model.JournalDetails()
                        {
                            JournalName = result.Result,
                            JournalData = data
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                var answer = JsonAnswer();
                answer.FromException(ex);
                return(ReturnJson(answer));
            }
        }