Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Box
{
public interface IAsset
{
@ro31337
ro31337 / gist:e6e9fbe29a4d2463a4f0
Created August 3, 2014 10:19
xmpp4r-simple.rb on Ruby 1.9+
...
presence = case new_presence.type
when nil
new_presence.show || :online
when :unavailable
:unavailable
else
nil
end
...
@ro31337
ro31337 / gist:237f982080a859ef9a44
Last active October 31, 2022 18:04
Install ssl certificates for winfows (to avoid error on Windows OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed). Make sure you added SSL_CERT_FILE environment variable!
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"
public class CompanyService
{
// ...
public Company GetById(long companyId)
{
return dbContext
.Companies
.FirstOrDefault(x => x.Id == companyId && !x.IsDeleted);
}
public class CompanyService
{
// ...
public Company GetById(long companyId)
{
return dbContext
.Companies
.FirstOrDefault(x => x.Id == companyId);
}
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);
}
public class CompanyService
{
// ...
public Delete(long companyId)
{
var company = GetById(companyId);
company.IsDeleted = true;
database.SaveChanges();
}
}
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();
}
public class MyContext : DbContext
{
//...
public override int SaveChanges()
{
foreach (var entry in ChangeTracker.Entries()
.Where(p => p.State == EntityState.Deleted))
SoftDelete(entry);
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",