public async Task <ActionResult> SubmitBooking(BookingFormModel formModel)
        {
            var lab_id  = int.Parse(TempData["LabID"].ToString());
            var user_id = int.Parse(HttpContext.Request.Cookies["userID"]);

            var time_id = formModel.time_am + formModel.time_pm;

            var items = await ItemDB.GetAvailableItems(formModel.book_date);

            items.RemoveAll(item => item.type != formModel.item_type);

            switch (time_id)
            {
            case 1:
                items.RemoveAll(item => item.time_am == false);
                break;

            case 2:
                items.RemoveAll(item => item.time_pm == false);
                break;

            case 3:
                items.RemoveAll(item => item.time_am == false || item.time_pm == false);
                break;

            default:
                break;
            }

            if (items.Count > 0)
            {
                for (var i = 0; i < formModel.quantity; ++i)
                {
                    var temp = TransactionDB.Add(new Transaction(user_id, items[i].uuid, (int)Transaction_type.borrow, time_id, formModel.book_date)).Result;
                    if (temp == 1)
                    {
                        TempData["BookingSucceed"] = false;
                        return(RedirectToAction("Booking", new { labID = lab_id }));
                    }
                }
            }

            return(RedirectToAction("Index", "User"));
        }
Example #2
0
    public void BuildingAdded(Building building)
    {
        //Is the building a constructor?
        if (building.ID == 0 || building.ID == 2)
        {
            m_GUIManager.AddConstructor(building);
        }

        if (m_Buildings.Count == 0 || m_Buildings.FirstOrDefault(x => x.ID == building.ID) == null)
        {
            //This is a new building, need to update available items
            m_AvailableItems.AddRange(ItemDB.GetAvailableItems(building.ID, m_Buildings));

            //Tell all the contents to update themselves
            m_GUIManager.UpdateQueueContents(m_AvailableItems);
        }

        m_Buildings.Add(building);
    }
Example #3
0
        public async Task <ActionResult <List <ItemsLaboratoryTransaction> > > Gets(string datetime_str)  // not sure about "Item"
        {
            DateTime booking_datetime = DateTime.ParseExact(datetime_str, "yyyy-MM-dd", null);

            return(await ItemDB.GetAvailableItems(booking_datetime));
        }