예제 #1
0
        public IActionResult InsertOrder(InsertOrderRequest request, int id)
        {
            var res = _service.InsertOrder(request, id);

            if (!(res is null))
            {
                return(Ok(res));
            }
예제 #2
0
        public override Order Insert(InsertOrderRequest request)
        {
            Database.Orders order = new Orders();
            order.Total         = request.NumberOfTickets * request.Appointment.Price;
            order.UserId        = request.UserId;
            order.AppointmentId = request.Appointment.AppointmentId;
            foreach (var product in request.Products)
            {
                order.Total += product.Price;
                Database.OrderProducts newItem = new OrderProducts()
                {
                    Order     = order,
                    ProductId = product.ProductId
                };
                _context.OrderProducts.Add(newItem);
            }
            Helper helper = new Helper(_context);

            for (var i = 0; i < request.NumberOfTickets; i++)
            {
                Database.Tickets newTicket = new Tickets()
                {
                    DateTime = DateTime.Now,
                    Order    = order,
                    Seat     = helper.RandomString(5)
                };
                _context.Tickets.Add(newTicket);
            }

            _context.Orders.Add(order);
            _context.Appointments.Find(request.Appointment.AppointmentId).SoldSeats += request.NumberOfTickets;
            _context.SaveChanges();

            var app = _context.Appointments.Include(a => a.CinemaDayMovie).ThenInclude(cdm => cdm.Movie).Single(a => a.AppointmentId == request.Appointment.AppointmentId);

            Database.Notifications notification = new Notifications()
            {
                Created = DateTime.Now,
                Type    = "Order",
                Content = $"{_context.Users.Find(request.UserId).FirstName} {_context.Users.Find(request.UserId).LastName} placed an order for '{app.CinemaDayMovie.Movie.Title}' of {order.Total}"
            };
            _context.Notifications.Add(notification);
            Database.UsersNotifications not = new UsersNotifications()
            {
                Notification = notification,
                UserId       = request.UserId
            };
            _context.UsersNotifications.Add(not);
            _context.SaveChanges();

            return(_mapper.Map <Model.Order>(order));
        }
예제 #3
0
파일: Proxy.cs 프로젝트: willdarwin/tta
        /// <summary>
        /// Insert a piece of order and return the orderid  --by Eric
        /// </summary>
        /// <param name="order"></param>
        /// <returns>Inserted order </returns>
        public OrderBE InsertOrder(OrderBE order)
        {
            InsertOrderRequest request = new InsertOrderRequest();

            request.OrderBE = order;
            InsertOrderResponse response = MyChannelFactory.CreateChannel().InsertOrder(request);

            if (response != null)
            {
                if (response.IsFailed == true)
                {
                    throw (new Exception(response.Message));
                }
            }
            return(response.OrderBE);
        }
예제 #4
0
        /// <summary>
        /// Insert orderdetails
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public InsertOrderResponse InsertOrder(InsertOrderRequest request)
        {
            OrderDetailsService service  = new OrderDetailsService();
            InsertOrderResponse response = new InsertOrderResponse();

            try
            {
                response.OrderBE = service.InsertOrder(request.OrderBE);
            }
            catch (Exception ex)
            {
                response.Message  = ex.Message;
                response.IsFailed = true;
            }
            return(response);
        }
예제 #5
0
        /// <summary>
        /// Insert a piece of order and return the orderid  --by Eric
        /// </summary>
        /// <param name="order"></param>
        /// <returns>Inserted order </returns>
        public OrderBE InsertOrder(OrderBE order)
        {
            InsertOrderRequest request = new InsertOrderRequest();

            request.OrderBE = order;
            InsertOrderResponse response = MyChannelFactory.CreateChannel().InsertOrder(request);

            if (response != null)
            {
                if (response.IsFailed == true)
                {
                    ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                    log.Error("error", new Exception(response.Message));
                    log.Fatal("fatal", new Exception(response.Message));
                    throw (new Exception(response.Message));
                }
            }
            return(response.OrderBE);
        }
예제 #6
0
        public string InsertOrder(InsertOrderRequest request, int customerId)
        {
            using (var trans = _context.Database.BeginTransaction())
            {
                //var orderId = _context.Orders.Count() + 1;
                var orderId = _context.Orders.Select(o => o.IdOrder).Max() + 1;


                if (request.Confectionery is null || request.Notes is null)
                {
                    trans.Rollback();
                    return(null);
                }
                try
                {
                    var Order = new Order
                    {
                        DateAccepted = request.DateAccepted,
                        DateFinished = DateTime.Now,
                        Notes        = request.Notes,
                        IdClient     = customerId
                    };

                    _context.Orders.Add(Order);
                    _context.SaveChanges();


                    // check if confectionary already exists in database if it does add to Confectionary_Order
                    foreach (var confec in request.Confectionery)
                    {
                        var confecId = _context.Confectionaries.Where(c => c.Name.Equals(confec.Name)).Select(c => c.IdConfectionary).FirstOrDefault();
                        if (confecId == 0)
                        {
                            trans.Rollback();
                            return(null);
                        }

                        // else add to confictionary_order
                        var confecOrder = new Confectionary_Order
                        {
                            IdConfection = confecId,
                            IdOrder      = orderId,
                            Quantity     = confec.Quantity,
                            Notes        = confec.Notes
                        };

                        _context.confectionary_Orders.Add(confecOrder);
                        _context.SaveChanges();
                    }

                    trans.Commit();

                    return("Order has been successfully created!");
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    return(null);
                }
            }
        }