Beispiel #1
0
        public ActionResult AskForDeliveryBoy([Bind(Include = "Id,GroupedOrderId,GroupedOrder,LimitDateTime")] GroupedOrderEventAskDeliveryBoy groupedOrderEventAskDeliveryBoy)
        {
            var dbGroupedOrder = db.GroupedOrders.Single(go => go.Id == groupedOrderEventAskDeliveryBoy.GroupedOrderId);
            var currentUserId  = User.Identity.GetUserId();

            if (dbGroupedOrder.Orders.All(o => o.CreateUser_Id != currentUserId))
            {
                ModelState.AddModelError("DeliveryBoy", "You have to join this order before becoming delivery boy.");
            }
            if (dbGroupedOrder.GroupedOrderEvents.Any(goe =>
                                                      goe.CreateUserId == currentUserId &&
                                                      goe.EventStatus == GroupedOrderEventStatus.Submitted))
            {
                ModelState.AddModelError("DeliveryBoy", "You have already submit a request to become delivery boy.");
            }

            if (ModelState.IsValid)
            {
                var currentGroupedOrderDeliveryBoy = db.Users.Single(u => u.Id == dbGroupedOrder.DeliveryBoy_Id);

                groupedOrderEventAskDeliveryBoy.GroupedOrder = null;
                groupedOrderEventAskDeliveryBoy.CreationDate = DateTime.UtcNow;
                groupedOrderEventAskDeliveryBoy.CreateUserId = currentUserId;
                groupedOrderEventAskDeliveryBoy.EventType    = EventType.BecomingDeliveryBoy;
                groupedOrderEventAskDeliveryBoy.Users        = new List <ApplicationUser> {
                    currentGroupedOrderDeliveryBoy
                };
                groupedOrderEventAskDeliveryBoy.EventStatus = GroupedOrderEventStatus.Submitted;

                db.Entry(groupedOrderEventAskDeliveryBoy).State = EntityState.Added;
                db.SaveChanges();

                var description = "{0} asked {1} to become delivery boy on {2}. {3}";

                groupedOrderEventAskDeliveryBoy.Description     = description;
                db.Entry(groupedOrderEventAskDeliveryBoy).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index", "GroupedOrders"));
            }

            return(View(groupedOrderEventAskDeliveryBoy));
        }
Beispiel #2
0
        /// <summary>
        /// GET: DeliveryBoy/AskForDeliveryBoy
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult AskForDeliveryBoy(Guid id)
        {
            var groupedOrder = db.GroupedOrders.Single(go => go.Id == id);

            var newDate = DateTime.UtcNow.AddMinutes(15);

            if (groupedOrder.DeliveryBoy == null)
            {
                groupedOrder.LimitDate = newDate;
                return(View("BecomingDeliveryBoy", groupedOrder));
            }

            var groupedOrderEvent = new GroupedOrderEventAskDeliveryBoy
            {
                LimitDateTime  = newDate,
                GroupedOrderId = groupedOrder.Id,
                GroupedOrder   = groupedOrder
            };

            return(View("AskForDeliveryBoy", groupedOrderEvent));
        }
Beispiel #3
0
        public ActionResult AcceptDeliveryBoyRequest(
            [Bind(Include = "Id,CreateUserId,CreateUser,GroupedOrderId,GroupedOrder,LimitDateTime")] GroupedOrderEventAskDeliveryBoy groupedOrderEventAskDeliveryBoy)
        {
            if (ModelState.IsValid)
            {
                // Mise à jour de la commande groupée
                var dbGroupedOrder = db.GroupedOrders.Single(go => go.Id == groupedOrderEventAskDeliveryBoy.GroupedOrderId);
                dbGroupedOrder.DeliveryBoy_Id  = groupedOrderEventAskDeliveryBoy.CreateUserId;
                dbGroupedOrder.LimitDate       = groupedOrderEventAskDeliveryBoy.LimitDateTime;
                db.Entry(dbGroupedOrder).State = EntityState.Modified;

                //Mise à jour de l'event de demande de DeliveryBoy
                var dbGroupedOrderEvent = db.GroupedOrderEvents.Single(goe => goe.Id == groupedOrderEventAskDeliveryBoy.Id);
                dbGroupedOrderEvent.EventStatus     = GroupedOrderEventStatus.Accepted;
                db.Entry(dbGroupedOrderEvent).State = EntityState.Modified;

                // Création d'un evenement d'acceptation de la demande
                var newDeliveryBoy       = db.Users.Single(u => u.Id == groupedOrderEventAskDeliveryBoy.CreateUserId);
                var newGroupedOrderEvent = new GroupedOrderEvent
                {
                    CreateUserId   = User.Identity.GetUserId(),
                    CreationDate   = DateTime.UtcNow,
                    Description    = "Delivery Boy Request accepted by {0}.",
                    EventStatus    = GroupedOrderEventStatus.Accepted,
                    EventType      = EventType.AcceptDeliveryBoyRequest,
                    GroupedOrderId = groupedOrderEventAskDeliveryBoy.GroupedOrderId,
                    Users          = new List <ApplicationUser> {
                        newDeliveryBoy
                    }
                };
                db.Entry(newGroupedOrderEvent).State = EntityState.Added;

                db.SaveChanges();

                return(RedirectToAction("Details", "GroupedOrders",
                                        new { Id = groupedOrderEventAskDeliveryBoy.GroupedOrderId }));
            }

            return(View(groupedOrderEventAskDeliveryBoy));
        }