public string Save(string id, string word, string translation, User owner) { if (string.IsNullOrEmpty(word) || string.IsNullOrEmpty(translation) || owner == null) { throw new ArgumentException("Word, translation or user is null"); } if (string.IsNullOrEmpty(id)) { return Create(word, translation, owner); } else { var card = GetCardByID(id); if (card != null && card.Owner.Id == owner.Id) { return Update(card, word, translation); } else { return Create(word, translation, owner); } } }
private string Create(string word, string translation, User owner) { var card = new Card {Word = word, Translation = translation, Owner = owner}; card = Algorithm.InitCard(card); card = cardRepo.Add(card); return card.Id; }