/// <summary> /// Adds a question /// </summary> /// <param name="qyfEntities">Entity context</param> /// <param name="idOwner">User id of the owner</param> /// <param name="idReceiver">User id of the receiver</param> /// <param name="text">Question content</param> /// <param name="anonPrice">Price to anonymize</param> /// <param name="privatePrice">Price to privatize</param> /// <param name="datePub">Publication date</param> /// <returns>The id of the created Question</returns> public static int Create(QuestionYourFriendsEntities qyfEntities, int idOwner, int idReceiver, string text, int anonPrice, int privatePrice, DateTime datePub) { try { _logger.InfoFormat("New question creation: owner({0}), receiver({1}), text({2}), anon({3}), priv({4}), datePub({5})", idOwner, idReceiver, text, anonPrice, privatePrice, datePub); var question = new QuestionYourFriendsDataAccess.Question { OwnerReference = { EntityKey = new EntityKey("QuestionYourFriendsEntities.Users", "id", idOwner) }, ReceiverReference = { EntityKey = new EntityKey("QuestionYourFriendsEntities.Users", "id", idReceiver) }, text = text, answer = null, anom_price = anonPrice, private_price = privatePrice, undesirable = false, date_pub = datePub, date_answer = null, deleted = false }; qyfEntities.AddToQuestions(question); qyfEntities.SaveChanges(); _logger.InfoFormat("New question id: {0}", question.id); return question.id; } catch (Exception ex) { _logger.Error("Cannot create a new question", ex); throw new ApplicationException("A database error occured during the operation."); } }
/// <summary> /// Adds a question /// </summary> /// <param name="qyfEntities">Entity context</param> /// <param name="q">Question to add</param> /// <returns>The id of the created Question</returns> public static int Create(QuestionYourFriendsEntities qyfEntities, QuestionYourFriendsDataAccess.Question q) { try { _logger.InfoFormat("New question creation: owner({0}), receiver({1}), text({2}), anon({3}), priv({4}), datePub({5})", q.Owner.id, q.Receiver.id, q.text, q.anom_price, q.private_price, q.date_pub); qyfEntities.AddToQuestions(q); qyfEntities.SaveChanges(); _logger.InfoFormat("New question id: {0}", q.id); return q.id; } catch (Exception ex) { _logger.Error("Cannot create a new question", ex); throw new ApplicationException("A database error occured during the operation."); } }