コード例 #1
0
 public ShoppingCart Create()
 {
     try
     {
         ShoppingCart shoppingCart = new ShoppingCart();
         dbContext.ShoppingCarts.Add(shoppingCart);
         dbContext.SaveChanges();
         return(shoppingCart);
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #2
0
 /// <summary>
 /// Add a message to the database
 /// </summary>
 /// <param name="message">Reference to a message object</param>
 /// <returns>True if the operation succeed, if not returns false.</returns>
 public bool AddMessage(Message message)
 {
     try
     {
         dbContext.Messages.Add(message);
         dbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #3
0
 public bool AddOrder(Order order, List <ProductOrder> productOrders)
 {
     try
     {
         dbContext.Orders.Add(order);
         dbContext.ProductOrders.AddRange(productOrders);
         dbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #4
0
        /// <summary>
        /// Add a Subscription to the Database
        /// </summary>
        /// <param name="name">Reference of the subscription's name</param>
        /// <param name="email">Reference of the subscription's email</param>
        /// <returns>True if the operation succeed, if not returns false.</returns>
        public bool AddSubscription(string name, string email)
        {
            try
            {
                Subscription subscription = new Subscription()
                {
                    // Name = name
                    Email = email
                };

                // Check if the email doesn't already exist
                if (!dbContext.Subscriptions.Any(s => s.Email.Equals(email)))
                {
                    dbContext.Subscriptions.Add(subscription);
                    dbContext.SaveChanges();
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }