Ejemplo n.º 1
0
    public async Task <Guid?> NewLog(string name, string message, string initiator, RequestServerBO requestServer, LogType logType = LogType.ApplicationServiceLog, GenericPriorityType priorityType = GenericPriorityType.Information)
    {
        var entity = await _dataLayer.TblApplications
                     .AsNoTracking()
                     .AsSplitQuery()
                     .FirstOrDefaultAsync(i => i.Guid == $"{requestServer.ApplicationId}");

        if (entity is null)
        {
            throw new ArgumentException($"Application with Guid '{requestServer.ApplicationId}' does not exist in any tenants");
        }

        var log = new TblLog()
        {
            ApplicationId = entity.Id,
            Initiator     = initiator,
            Severity      = (short)priorityType,
            Message       = message,
            Name          = name,
            Type          = (short?)logType,
            Uuid          = requestServer.RequestId.ToString()
        };

        _dataLayer.TblLogs.Add(log);
        await _dataLayer.SaveChangesAsync();

        return(requestServer.RequestId);
    }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(Guid id, [Bind("LogId,CreateDate,MapmenuId,Data")] TblLog tblLog)
        {
            if (id != tblLog.LogId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tblLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TblLogExists(tblLog.LogId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MapmenuId"] = new SelectList(_context.TblMapMenu, "Id", "Id", tblLog.MapmenuId);
            return(View(tblLog));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <TblLog> > PostTblLog(TblLog tblLog)
        {
            _context.TblLogs.Add(tblLog);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTblLog", new { id = tblLog.LogId }, tblLog));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutTblLog(int id, TblLog tblLog)
        {
            if (id != tblLog.LogId)
            {
                return(BadRequest());
            }

            _context.Entry(tblLog).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TblLogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 5
0
        public static void WriteSession(string username)
        {
            //Ghi dữ liệu log
            TblLog log = new TblLog();

            log.UserName = username;
            log.FromTime = DateTime.Now;
            new TblLogDao().Create(log);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("LogId,CreateDate,MapmenuId,Data")] TblLog tblLog)
        {
            if (ModelState.IsValid)
            {
                tblLog.LogId = Guid.NewGuid();
                _context.Add(tblLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MapmenuId"] = new SelectList(_context.TblMapMenu, "Id", "Id", tblLog.MapmenuId);
            return(View(tblLog));
        }
Ejemplo n.º 7
0
 public TblLog GetByPrimaryKey(int logID)
 {
     try
     {
         string query  = "select * from TblLog where LogID = " + logID;
         TblLog tblLog = connect.Query <TblLog>(query).FirstOrDefault <TblLog>();
         return(tblLog);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(null);
     }
 }
Ejemplo n.º 8
0
        public async Task <bool> InsertAsync(TblLog log)
        {
            try
            {
                await _context.AddAsync(log);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
        public async Task <Guid?> NewLog(string name, string message, string initiator, RequestServerBO requestServer, LogType logType = LogType.ApplicationServiceLog, GenericPriorityType priorityType = GenericPriorityType.Information)
        {
            var log = new TblLog()
            {
                ApplicationId = requestServer.ApplicationId,
                Initiator     = initiator,
                Severity      = (short)priorityType,
                Message       = message,
                Name          = name,
                Type          = (short?)logType,
                Uuid          = requestServer.Guid.ToString()
            };

            _dataLayer.TblLogs.Add(log);
            await _dataLayer.SaveChangesAsync();

            return(requestServer.Guid);
        }
        public async Task InsertAsync()
        {
            // Arrange
            var nombreDb = Guid.NewGuid().ToString();
            var context  = ConstruirContext(nombreDb);

            var log   = new LogRespository(context);
            var datos = new TblLog {
                Cedula = "1065",
                Fecha  = DateTime.Now,
                Traza  = "Case #1: 2\nCase #2: 1\nCase #3: 2\nCase #4: 3\nCase #5: 8\n"
            };

            // Act
            var resultado = await log.InsertAsync(datos);

            // Assert
            Assert.True(resultado);
        }
Ejemplo n.º 11
0
 public static void WriteGeneralLog(string Server_Url, string Ip, int Uid, string UserIdentity)
 {
     try
     {
         AngleDBDataContext context = new AngleDBDataContext();
         TblLog             log     = new TblLog
         {
             Datetime     = CustDateTime.GetCurrentDateTime(),
             Server_Url   = Server_Url,
             Ip           = Ip,
             UserIdentity = UserIdentity,
             User_Id      = Uid,
             Website      = "Dx"
         };
         context.TblLogs.InsertOnSubmit(log);
         context.SubmitChanges();
     }
     catch (Exception ex)
     {
         ExceptionLog.WriteException(ex, "UserSideLog", "WriteGeneralLog", Uid, Server_Url, Ip, UserIdentity);
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Author: Phạm Huy Hùng
        /// Todo: tìm kiếm đối tượng theo khóa chính
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public TblLog FindById(TblLog obj)
        {
            try
            {
                using (TkSchoolDbContext db = new TkSchoolDbContext())
                {
                    return db.TblLogs.SingleOrDefault(x => x.LogId == obj.LogId);
                }
            }

            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    throw new Exception("TblLogDao::FindById::" + ex.Message);
                }
                else
                {
                    throw new Exception("TblLogDao::FindByID::" + ex.InnerException.Message);
                }
            }
        }
Ejemplo n.º 13
0
 public void Create(TblLog o)
 {
     try
     {
         using (TkSchoolDbContext db = new TkSchoolDbContext())
         {
             var res = db.TblLogs.Where(x => x.LogId == o.LogId).SingleOrDefault();
             db.TblLogs.Add(res);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException == null)
         {
             throw new Exception("TblLogDao::FindByAll::" + ex.Message);
         }
         else
         {
             throw new Exception("TblLogDao::FindByAll::" + ex.InnerException.Message);
         }
     }
 }