This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Box | |
{ | |
public interface IAsset | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
presence = case new_presence.type | |
when nil | |
new_presence.show || :online | |
when :unavailable | |
:unavailable | |
else | |
nil | |
end | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
ruby_install_dir = 'c:\Ruby200-x64' | |
cacert_file = "#{ruby_install_dir}\\cacert.pem" | |
Net::HTTP.start("curl.haxx.se") do |http| | |
resp = http.get("/ca/cacert.pem") | |
if resp.code == "200" | |
open(cacert_file, "wb") { |file| file.write(resp.body) } | |
puts "\n\nA bundle of certificate authorities has been installed to" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CompanyService | |
{ | |
// ... | |
public Company GetById(long companyId) | |
{ | |
return dbContext | |
.Companies | |
.FirstOrDefault(x => x.Id == companyId && !x.IsDeleted); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CompanyService | |
{ | |
// ... | |
public Company GetById(long companyId) | |
{ | |
return dbContext | |
.Companies | |
.FirstOrDefault(x => x.Id == companyId); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyContext : DbContext | |
{ | |
public virtual IDbSet<Company> Companies { get; set; } | |
protected override void OnModelCreating(DbModelBuilder modelBuilder) | |
{ | |
modelBuilder.Entity<Company>() | |
.Map(m => m.Requires("IsDeleted").HasValue(false)) | |
.Ignore(m => m.IsDeleted); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CompanyService | |
{ | |
// ... | |
public Delete(long companyId) | |
{ | |
var company = GetById(companyId); | |
company.IsDeleted = true; | |
database.SaveChanges(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CompanyService | |
{ | |
// ... | |
public Delete(long companyId) | |
{ | |
var company = GetById(companyId); | |
company.DeletedAtUtc = DateTimeOffset.Now; | |
database.Companies.Remove(company); // it's like we usually delete | |
database.SaveChanges(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyContext : DbContext | |
{ | |
//... | |
public override int SaveChanges() | |
{ | |
foreach (var entry in ChangeTracker.Entries() | |
.Where(p => p.State == EntityState.Deleted)) | |
SoftDelete(entry); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SoftDelete(DbEntityEntry entry) | |
{ | |
Type entryEntityType = entry.Entity.GetType(); | |
string tableName = GetTableName(entryEntityType); | |
string primaryKeyName = GetPrimaryKeyName(entryEntityType); | |
string sql = | |
string.Format( | |
"UPDATE {0} SET IsDeleted = 1 WHERE {1} = @id", |
OlderNewer