// returns CardId (int) private static Result AddCard(string email, string text, string backText) { Result result = new Result(); using (ForGoodEntities db = new ForGoodEntities()) { User user = db.Users.First(u => u.Email == email); Card card = new Card() { Text = text, BackText = backText, CreationDateUtc = DateTime.UtcNow, DueDateUtc = DateTime.UtcNow, User = user }; db.AddToCards(card); db.SaveChanges(); result.Code = RESULT_CODES.Succeeded; result.ReturnedObj = card.CardId; } return result; }
// returns a Card (CoCard) private static Result GetNextToDueCard(string email) { Result result = new Result(); using (ForGoodEntities db = new ForGoodEntities()) { var query = db.Cards.Where(c => c.User.Email == email && c.DueDateUtc < DateTime.UtcNow).OrderBy(c => c.DueDateUtc); Card card = new Card(); //CoCard coCard = new CoCard(); if (query.Count() > 0) { card = query.First(); result.Code = RESULT_CODES.Succeeded; result.ReturnedObj = MapToCustomObject(card) as CoCard; } else { result.Code = RESULT_CODES.Failed; result.ErrorCodes = new List<int>(){ ERROR_CODES.GetNextToDueCard_NoMoreCards }; } } return result; }