Exemplo n.º 1
0
        public async Task <IActionResult> PutRentalOrders(int id, RentalOrders rentalOrders)
        {
            if (id != rentalOrders.Id)
            {
                return(BadRequest());
            }

            _context.Entry(rentalOrders).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RentalOrdersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        /// <summary>
        /// Sends out notifications to contact people whos machines are going to be offrented in two days
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendNotifications(object sender, ElapsedEventArgs e)
        {
            DAL _database = new DAL();

            IEnumerable <TrackUnitData> units = _database.GetTrackUnitData();

            string[] dataBases = ConfigurationManager.AppSettings["DataBasePrefix"].Split(',');


            //Get each database off rent orders
            foreach (string dataBase in dataBases)
            {
                RentalOrders rentalOrders = new RentalOrders()
                {
                    Orders = _database.GetRentalOrdersByOffRent(dataBase, DateTime.Now.AddDays(int.Parse(ConfigurationManager.AppSettings["XDaysBefore"])))
                };
                rentalOrders.Orders = rentalOrders.Process(units, rentalOrders.Orders);

                //Remove Rental Orders with missing contact emails
                rentalOrders.Orders = rentalOrders.Orders.Where(i => !string.IsNullOrWhiteSpace(i.ContactEmail));

                //Go thourgh each of the orders
                foreach (RentalOrder order in rentalOrders.Orders)
                {
                    PushNotification notification = new PushNotification()
                    {
                        email               = order.ContactEmail,
                        notificationType    = "OFF_RENT",
                        CustAccount         = order.CustAccount,
                        AccountName         = order.AccountName,
                        SalesId             = order.SalesId,
                        PurchOrderFormNum   = order.PurchOrderFormNum,
                        AssetOverviewItemId = order.AssetOverviewItemId,
                        LineDescription     = order.LineDescription,
                        DateOnHire          = order.DateOnHire,
                        DateOffHire         = order.DateOffHire.Value,
                        ExpectedDateOffHire = order.ExpectedDateOffHire,
                        AssetId             = order.AssetId,
                        DeliveryName        = order.DeliveryName,
                        DeliveryCity        = order.DeliveryCity,
                        DeliveryAddress     = order.DeliveryAddress,
                        ProductId           = order.ProductId,
                        OrderStatusId       = order.OrderStatusId,
                        ContactPerson       = order.ContactPerson,
                        ContactPhone        = order.ContactPhone,
                        OperatorNameId      = order.OperatorNameId,
                        OperatorName        = order.OperatorName,
                        OperatorPhoneNumber = order.OperatorPhoneNumber,
                        InventTransId       = order.InventTransId,
                        PriceRateCode       = order.PriceRateCode,
                        Latitude            = order.Latitude,
                        Longitude           = order.Longitude,
                        CanChangeOffHire    = false,
                        CanChangeOnHire     = false
                    };
                    notification.Send();
                }
            }
            ScheduleNextExecution();
        }
Exemplo n.º 3
0
        public async Task <ActionResult <RentalOrders> > PostRentalOrders(RentalOrders rentalOrders)
        {
            _context.RentalOrders.Add(rentalOrders);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (RentalOrdersExists(rentalOrders.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetRentalOrders", new { id = rentalOrders.Id }, rentalOrders));
        }