public string CreateScribble(Scribble scribble) { Check.If(scribble).IsNotNull(); if (scribble.ApplicationReference.IsNullOrEmpty()) return null; var result = _scribbleRepository.CreateOrUpdateScribble(scribble); return result ? scribble.ApplicationReference : null; }
public bool CreateOrUpdateScribble(Scribble scribble) { var existingScribble = _scribbleContext.Scribbles.Active() .FirstOrDefault( s => s.ApplicationReference == scribble.ApplicationReference && s.Username == scribble.Username); //if it already exists, soft delete it. if (existingScribble.IsNotNull()) { existingScribble.SoftDelete(); } _scribbleContext.Scribbles.Add(scribble); return _scribbleContext.SaveChanges() > 0; }