public bool UpdateDomain(ErrorLogDataAccess.DataClasses.Domain domainObj) { using (TransactionScope scope1 = new TransactionScope()) { try { string formattedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture); var domainCollection = mongoDatabaseRunTime.GetCollection <ErrorLogDataAccess.DataClasses.Domain>("Domain"); var filterObj = Builders <ErrorLogDataAccess.DataClasses.Domain> .Filter.Eq("DomainCode", domainObj.DomainCode); var updateObj = Builders <ErrorLogDataAccess.DataClasses.Domain> .Update .Set("DomainName", domainObj.DomainName) .Set("DomainDescription", domainObj.DomainDescription) .Set("IsActive", domainObj.IsActive) .Set("LastUpdatedDate", formattedDate) .CurrentDate("lastModified"); domainCollection.UpdateOne(filterObj, updateObj); scope1.Complete(); return(true); } catch (Exception ex) { scope1.Dispose(); throw; } } }
//save using a 'Domain' type variable public bool SaveDomain(ErrorLogDataAccess.DataClasses.Domain domainObj, int userId = 1) { using (TransactionScope scope1 = new TransactionScope()) { try { string formattedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture); var DomainCollection = mongoDatabaseRunTime.GetCollection <ErrorLogDataAccess.DataClasses.Domain>("Domain"); var domainRow = new ErrorLogDataAccess.DataClasses.Domain() { DomainId = GetNewDomainID(), DomainCode = domainObj.DomainCode, DomainName = domainObj.DomainName, DomainDescription = domainObj.DomainDescription, IsActive = domainObj.IsActive, EntryDate = formattedDate, UserId = 1 }; DomainCollection.InsertOne(domainRow); scope1.Complete(); return(true); } catch (Exception) { scope1.Dispose(); throw; } } }