public ActionResult Join(NewJoining newJoining)
 {
     if (newJoining.OrderID != 0)
     {
         string       id   = User.Identity.GetUserId();
         AbstractUser user = db.AllUsers.OfType <AuthorizedUser>().Where(x => x.AppUser.Id == id).FirstOrDefault();
         if (user == null)
         {
             user           = new UnauthorizedUser();
             user.FirstName = newJoining.UserFirstName;
             user.LastName  = newJoining.UserLastName;
             db.AllUsers.Add(user);
             db.SaveChanges();
         }
         if (newJoining.UserFirstName == null || newJoining.UserLastName == null)
         {
             newJoining.UserFirstName = user.FirstName;
             newJoining.UserLastName  = user.LastName;
         }
         Order   order   = db.Orders.Where(x => x.Id == newJoining.OrderID).FirstOrDefault();
         Joining joining = new Joining();
         joining.Order   = order;
         joining.OrderId = order.Id;
         joining.User    = user;
         joining.UserId  = user.Id;
         joining.Text    = newJoining.Text;
         db.Joinings.Add(joining);
         db.SaveChanges();
         order.Joinings.Add(joining);
         db.SaveChanges();
         user.Joinings.Add(joining);
         db.SaveChanges();
     }
     return(RedirectToAction("Index", "Order"));
 }
        public void JoiningEdit(Joining newJoining)
        {
            Joining joining = db.Joinings.Find(newJoining.Id);

            if (joining != null)
            {
                joining.Text = newJoining.Text;
                db.SaveChanges();
            }
            Response.Write("<script>history.go(-1);</script>");
            //return RedirectToAction("Index", "Account");
        }
        public void JoiningDelete(int Id)
        {
            Joining joining = db.Joinings.Find(Id);

            if (joining != null)
            {
                db.Joinings.Remove(joining);
                db.SaveChanges();
            }
            Response.Write("<script>history.go(-1);</script>");
            //return RedirectToAction("Index", "Account");
        }
        public void TestJoining()
        {
            ObservableCollection <Item> leftItems = new ObservableCollection <Item>(
                new Item[]
            {
                new Item(10, "11"),
                new Item(10, "12"),
                new Item(20, "21"),
                new Item(30, "31"),
                new Item(30, "32"),
                new Item(30, "33")
            });

            ObservableCollection <Item> rightItems = new ObservableCollection <Item>(
                new Item[]
            {
                new Item(10, "10"),
                new Item(20, "20"),
                new Item(30, "30")
            });

            OcConsumer           consumer = new OcConsumer();
            Joining <Item, Item> joining  =
                leftItems.Joining(rightItems, (li, ri) => ri.Id == li.Id).For(consumer);

            Action <JoinPair <Item, Item>, Item> setLeftItemRequestHandler = (pair, item) =>
            {
                leftItems[joining.IndexOf(pair)] = item;
            };

            joining.SetLeftItemRequestHandler = setLeftItemRequestHandler;
            Assert.AreEqual(joining.SetLeftItemRequestHandler, setLeftItemRequestHandler);

            Action <JoinPair <Item, Item>, Item> setRightItemRequestHandler = (pair, item) =>
            {
                leftItems[leftItems.IndexOf(pair.LeftItem)] = item;
            };

            joining.SetRightItemRequestHandler = setRightItemRequestHandler;
            Assert.AreEqual(joining.SetRightItemRequestHandler, setRightItemRequestHandler);

            Assert.AreEqual(joining[2].Joining, joining);
            Assert.NotNull(joining[2].ToString());

            joining[2].LeftItem  = new Item(50, "50");
            joining[3].RightItem = new Item(70, "70");
            joining.ValidateInternalConsistency();
            consumer.Dispose();
        }
        public ActionResult Create(NewOrder model)
        {
            Order        order = new Order();
            AbstractUser user  = null;

            if (User.Identity.IsAuthenticated)
            {
                string id = User.Identity.GetUserId();
                IEnumerable <AuthorizedUser> u = db.AllUsers.OfType <AuthorizedUser>();
                user = u.FirstOrDefault(x => x.AppUserId == id);
                if (model.IsPrivate)
                {
                    order.IsPrivate = true;
                }
            }
            else
            {
                user           = new UnauthorizedUser();
                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;
                db.AllUsers.Add(user);
                db.SaveChanges();
            }
            order.Creator            = user;
            order.CreatorId          = user.Id;
            order.Address            = model.Address;
            order.CompletionDateTime = DateTime.Parse(model.Date + " " + model.Time);
            order.OrderPlace         = model.Place;
            order.IsPrivate          = model.IsPrivate;

            db.Orders.Add(order);
            db.SaveChanges();

            Joining join = new Joining();

            join.Order   = order;
            join.OrderId = order.Id;
            join.Text    = model.TextOfOrder;
            join.User    = user;
            join.UserId  = user.Id;
            db.Joinings.Add(join);
            db.SaveChanges();
            user.Orders.Add(order);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        private static void DemoPart1()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("1). Filtering: Onderstaande functies is een filtering van de 15 producten.");
            WhiteLine();
            Filtering.Intro();
            WhiteLine();
            Filtering.MethodHighTierProducts();
            Breaker();
            Filtering.QueryHighTierProducts();
            Breaker();

            Console.WriteLine("2). Ordering: Onderstaande functies is een ordering van 15 orders.");
            WhiteLine();
            Ordering.Intro();
            WhiteLine();
            Ordering.MethodByTotalPrice();
            Breaker();
            Ordering.QueryByTotalPrice();
            Breaker();

            Console.WriteLine("3). Projection: Onderstaande functies is een projectie van 15 customers.");
            WhiteLine();
            Projection.SelectIntro();
            WhiteLine();
            Projection.MethodSelectCustomerName();
            Breaker();
            Projection.QuerySelectCustomerName();
            Breaker();

            Projection.SelectManyIntro();
            WhiteLine();
            Projection.MethodSelectManyProductIds();
            Breaker();
            Projection.QuerySelectManyProductIds();
            Breaker();

            Console.WriteLine("4). Joining: Onderstaande functies is een joining van 15 producten, orders en customers.");
            WhiteLine();
            Joining.InnerJoinIntro();
            WhiteLine();
            Joining.MethodInnerCustomerOrderProducts();
            Breaker();
            Joining.QueryInnerCustomerOrderProducts();
            Breaker();

            Joining.OuterJoinIntro();
            WhiteLine();
            Joining.MethodOuterCustomerOrderProducts();
            Breaker();
            Joining.QueryOuterCustomerOrderProducts();
            Breaker();

            Console.WriteLine("5). Grouping: Onderstaande functies is een groupering van 15 orders.");
            WhiteLine();
            Grouping.Intro();
            WhiteLine();
            Grouping.MethodByShippingCost();
            Breaker();
            Grouping.QueryByShippingCost();
            Breaker();

            Console.WriteLine("6). Aggregates: Onderstaande functies zijn aggregates van 15 producten.");
            WhiteLine();
            Aggregates.CountIntro();
            WhiteLine();
            Aggregates.MethodCountByPrice();
            Breaker();
            Aggregates.QueryCountByPrice();
            Breaker();

            Aggregates.MinIntro();
            WhiteLine();
            Aggregates.MethodMinPrice();
            Breaker();
            Aggregates.QueryMinPrice();
            Breaker();

            Aggregates.MaxIntro();
            WhiteLine();
            Aggregates.MethodMaxPrice();
            Breaker();
            Aggregates.QueryMaxPrice();
            Breaker();

            Aggregates.SumIntro();
            WhiteLine();
            Aggregates.MethodSumPrice();
            Breaker();
            Aggregates.QuerySumPrice();
            Breaker();

            Aggregates.AverageIntro();
            WhiteLine();
            Aggregates.MethodAveragePrice();
            Breaker();
            Aggregates.QueryAveragePrice();
            Breaker();

            Console.WriteLine("7). Partitioning: Onderstaande functies zijn partitioning van 15 customers.");
            WhiteLine();
            Partitioning.TakeSkipIntro();
            WhiteLine();
            Partitioning.TakeFive();
            Breaker();
            Partitioning.SkipFive();
            Breaker();

            Partitioning.FirstFirstOrDefaultIntro();
            WhiteLine();
            Partitioning.FirstOnName();
            Breaker();
            Partitioning.FirstOnNameException();
            Breaker();
            Partitioning.FirstOrDefaultOnName();
            Breaker();

            Partitioning.DistinctIntro();
            WhiteLine();
            Partitioning.DistinctCustomers();
            Breaker();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("8). Deferred Execution: Onderstaande functies is het uitvoeren van deferred execution.");
            WhiteLine();
            DeferredExecution.Demo();
            Breaker();
        }