ปรับปรุงการทำ log
This commit is contained in:
@@ -8,6 +8,11 @@ using TTSW.Common;
|
||||
using TodoAPI2.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using IdentityModel;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using System.Data;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TTSW.Utils;
|
||||
|
||||
namespace TTSW.EF
|
||||
{
|
||||
@@ -16,6 +21,7 @@ namespace TTSW.EF
|
||||
{
|
||||
#region Private Variables
|
||||
private DataContext _context;
|
||||
private IMyDatabase _db;
|
||||
public DataContext Context
|
||||
{
|
||||
get
|
||||
@@ -36,11 +42,12 @@ namespace TTSW.EF
|
||||
}
|
||||
#endregion
|
||||
|
||||
public BaseRepository(DataContext context, IHttpContextAccessor contextAccessor
|
||||
public BaseRepository(DataContext context, IHttpContextAccessor contextAccessor, IMyDatabase mydatabase
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
_contextAccessor = contextAccessor;
|
||||
_db = mydatabase;
|
||||
}
|
||||
|
||||
#region Private Functions
|
||||
@@ -255,12 +262,24 @@ namespace TTSW.EF
|
||||
if (!SaveToDB())
|
||||
throw new NotificationException($"Unable to insert item to database.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public T Update(Key id, object model)
|
||||
{
|
||||
var userLogin = GetLoginProfile();
|
||||
|
||||
var existingItem = Get(id);
|
||||
var old_existingItem = Get(id);
|
||||
object old_existingItem;
|
||||
|
||||
try
|
||||
{
|
||||
var x = MyHelper.GetDataRow(id, model, _db);
|
||||
old_existingItem = MyHelper.GetObject(x, model.GetType().Name.Replace("Entity", ""));
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
old_existingItem = null;
|
||||
}
|
||||
|
||||
if (existingItem == null)
|
||||
throw new NotificationException($"No item in database.");
|
||||
|
||||
Reference in New Issue
Block a user