//======================================================== CREATE ============================================== #region public async Task <T> CreateNTU(T entity) { try { await _db.Set <T>().AddAsync(entity); await _db.SaveChangesAsync(); return(await Task.FromResult(entity)); } catch (Exception e) { return(await Task.FromResult <T>(null)); } }
/// =============================================== Create ====================================== /// <summary> /// Create entity. /// Before creating a new entity that is required to check if an entity already exists (email, phone, code, ...). /// If Checkvalue is false will insert success /// </summary> /// <param name="entity"></param> /// <param name="Checkvalue"></param> /// <returns>Entity</returns> #region public async Task <T> Create(T entity, bool CheckIsExist) { try { if (CheckIsExist) { return(await Task.FromResult <T>(null)); } await _db.Set <T>().AddAsync(entity); await _db.SaveChangesAsync(); return(await Task.FromResult(entity)); } catch (Exception e) { var error = e.Message; return(await Task.FromResult <T>(null)); } }