using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace sharpknife { public partial class BalanceLog { public BalanceLog() { Type = "Balance"; Date = DateTime.Today; CreatedOn = DateTime.Now; ModifiedOn = DateTime.Now; } public BalanceLog(string source) : this() { this.Source = source; } public void Save() { using (databaseEntities context = new databaseEntities()) { BalanceLog item = (from i in context.BalanceLog where i.Source == Source && (i.Date == this.Date) && i.Type == this.Type select i).FirstOrDefault(); if (item == null) { item = new BalanceLog(Source) { BalanceLogId = Guid.NewGuid(), Value = this.Value, Source = this.Source, Type = this.Type, Date = this.Date }; context.BalanceLog.AddObject(item); } else { item.ModifiedOn = DateTime.Now; item.Value = this.Value; } context.SaveChanges(); } } } }