Exemple #1
0
        public async Task <LogfileModel> SingleLogfile(int id)
        {
            LogfileModel logfile = new LogfileModel();

            using (var conn = new SqlConnection(_configuration.Value))
            {
                const string query = @"select * from dbo.Logfile where Id =@Id";

                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                try
                {
                    logfile = await conn.QueryFirstOrDefaultAsync <LogfileModel>(query, new { id }, commandType : CommandType.Text);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            return(logfile);
        }
Exemple #2
0
 public async Task <bool> EditLogfile(int id, LogfileModel logfile)
 {
     using (var conn = new SqlConnection(_configuration.Value))
     {
         const string query = @"update dbo.Logfile set Project = @Project where Id=@Id";
         if (conn.State == ConnectionState.Closed)
         {
             conn.Open();
         }
         try
         {
             await conn.ExecuteAsync(query, new { logfile.Project, id }, commandType : CommandType.Text);
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             if (conn.State == ConnectionState.Open)
             {
                 conn.Close();
             }
         }
     }
     return(true);
 }
        public async Task <IActionResult> Put(int id, LogfileModel logfilemodel)
        {
            try
            {
                await _logfileService.EditLogfile(id, logfilemodel);

                return(Ok());
            }
            catch
            {
                return(NotFound());
            }
        }
        public async Task <IActionResult> Post(LogfileModel logfilemodel)
        {
            try
            {
                await _logfileService.CreateLogfile(logfilemodel);

                return(Ok());
            }
            catch
            {
                return(NotFound());
            }
        }
Exemple #5
0
 public async Task <bool> CreateLogfile(LogfileModel logfile)
 {
     using (var conn = new SqlConnection(_configuration.Value))
     {
         const string query = @"insert into dbo.Logfile (CustomerId,Type,Phone,Staff,Status,CreateTime,RecordFile,CustomerName,Project,DurationTime,PhoneReceiver,DeviceId,Group,Company,createdAt) "
                              + "values (@CustomerId,@Type,@Phone,@Staff,@Status,@CreateTime,@RecordFile,@CustomerName,@Project,@DurationTime,@PhoneReceiver,@DeviceId,@Group,@Company,@createdAt)";
         if (conn.State == ConnectionState.Closed)
         {
             conn.Open();
         }
         try
         {
             await conn.ExecuteAsync(query, new
             {
                 logfile.CustomerId,
                 logfile.Type,
                 logfile.Phone,
                 logfile.Staff,
                 logfile.Status,
                 logfile.CreateTime,
                 logfile.RecordFile,
                 logfile.CustomerName,
                 logfile.Project,
                 logfile.DurationTime,
                 logfile.PhoneReceiver,
                 logfile.DeviceId,
                 logfile.Group,
                 logfile.Company,
                 logfile.createdAt
             }, commandType : CommandType.Text);
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             if (conn.State == ConnectionState.Open)
             {
                 conn.Close();
             }
         }
     }
     return(true);
 }