Beispiel #1
0
        public void AddItem(Plot plot)
        {
            var tempOrderId = GetTempOrderId();
            var order       = DataContext.Orders.FirstOrDefault(x => tempOrderId == x.Guid.ToString());

            if (order != null)
            {
                order.Plots.Add(plot);
            }
            else
            {
                var plotList = new EntitySet <Plot> {
                    plot
                };
                order = new Order()
                {
                    Guid  = new Guid(tempOrderId),
                    Plots = plotList
                };
                DataContext.Orders.InsertOnSubmit(order);
            }

            try
            {
                DataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public bool FinalizePurchase(string orderId)
        {
            var result = false;

            // Begin transaction
            using (var transaction = new TransactionScope())
            {
                try
                {
                    var dbOrder = DataContext.Orders.FirstOrDefault(x => new Guid(orderId) == x.Guid);
                    if (dbOrder == null)
                    {
                        throw new ArgumentException("Order Not Found");
                    }
                    dbOrder.DateOfCompletion = DateTime.Now;
                    DataContext.SubmitChanges();
                    result = true;
                    transaction.Complete();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return(result);
        }
Beispiel #3
0
        public int TieAccountClient(string email, string firstName, string lastName, DateTime dateOfBirth)
        {
            var userData = DataContext.AspNetUsers.FirstOrDefault(x => x.Email == email);
            var client   = new Client()
            {
                UserID      = userData.Id,
                DateOfBirth = dateOfBirth,
                FirstName   = firstName,
                LastName    = lastName
            };

            DataContext.Clients.InsertOnSubmit(client);

            DataContext.SubmitChanges();

            var dbClient = DataContext.Clients.First(x => x.UserID == client.UserID);

            return(dbClient.ClientID);
        }