public static CounterAction GetOrCreate(ProjectReportDemoCtx ctx, Guid id) { CounterAction result = ctx.CounterAction.SingleOrDefault(item => item.Id == id); if (result == null) { result = new CounterAction(); result.Id = id; ctx.CounterAction.Add(result); } return(result); }
public static BL.CounterAction MapMvcToBusiness(MVC.CounterAction source) { if (source == null) { return(null); } BL.CounterAction target = BL.CounterAction.GetOrCreate(MapSupport.ActiveCtx, source.CounterActionId); if (target.Version != Guid.Empty && target.Version != source.CounterActionVersion) { throw new DataException("Concurrency check failed"); } if (source.CounterActionIsDeleted) { target.Delete(MapSupport.ActiveCtx); return(null); } else { target.Version = source.CounterActionVersion; target.Text = source.CounterActionText; } return(target); }