예제 #1
0
        public int PutAdd(Models.RoomModel rm)
        {
            Room r = new Room(rm.name);

            roomList.Add(r);
            return(r.id);
        }
        public ActionResult Create(Models.RoomModel model)
        {
            // Obtain your OAuth token
            var accessToken = RequestItemsService.User.AccessToken;                      // Represents your {ACCESS_TOKEN}
            var basePath    = $"{RequestItemsService.Session.RoomsApiBasePath}/restapi"; // Base API path
            var accountId   = RequestItemsService.Session.AccountId;                     // Represents your {ACCOUNT_ID}

            try
            {
                // Mapping room model to match types
                var mappedRoomModel = new CreateRoomWithData.RoomModel
                {
                    Name       = model.Name,
                    TemplateId = model.TemplateId,
                    Templates  = model.Templates
                };

                //  Call the Rooms API to create a room
                var room = CreateRoomWithData.CreateRoom(basePath, accessToken, accountId, mappedRoomModel);

                // Show results
                ViewBag.h1          = "The room was successfully created";
                ViewBag.message     = $"The room was created! Room ID: {room.RoomId}, Name: {room.Name}.";
                ViewBag.Locals.Json = JsonConvert.SerializeObject(room, Formatting.Indented);

                return(View("example_done"));
            }
            catch (ApiException apiException)
            {
                ViewBag.errorCode    = apiException.ErrorCode;
                ViewBag.errorMessage = apiException.Message;

                return(View("Error"));
            }
        }
예제 #3
0
 public string GetEdit(int id, Models.RoomModel rm)
 {
     if (roomList.Exists(Room => Room.id == id))
     {
         Room rEdit = roomList.Find(Room => Room.id == id);
         rEdit.name = rm.name;
         return(rEdit.name);
     }
     else
     {
         return("Nie ma elementu o numerze " + id);
     }
 }
예제 #4
0
        private void CreateShopTable(List <Cart> purchaseList, out double subTotal)
        {
            subTotal = new Double();
            RoomModel model = new Models.RoomModel();

            foreach (Cart cart in purchaseList)
            {
                Room room = model.GetRoom(cart.RoomID);

                //crea the image button
                ImageButton btnImage = new ImageButton
                {
                    ImageUrl    = string.Format("~/Images/RoomImages/{0}", room.Image),
                    PostBackUrl = string.Format("~/Pages/Rooms.aspx?id={0}", room.Id),
                    CssClass    = "roomImage"
                };

                //create the delete link
                LinkButton lnkDelete = new LinkButton
                {
                    PostBackUrl = string.Format("~/Pages/ShoppingCart.aspx?roomId={0}", cart.ID),
                    Text        = "Delete Item",
                    ID          = "del" + cart.ID
                };

                //add an OnClick Event
                lnkDelete.Click += Delete_Item;

                //create the 'quantity ddl
                // generate list with numbers for each room available
                int[]        amount    = Enumerable.Range(1, 2).ToArray();
                DropDownList ddlAmount = new DropDownList
                {
                    DataSource           = amount,
                    AppendDataBoundItems = true,
                    AutoPostBack         = true,
                    ID = cart.ID.ToString()
                };

                ddlAmount.DataBind();
                ddlAmount.SelectedValue         = cart.Amount.ToString();
                ddlAmount.SelectedIndexChanged += ddlAmount_SelectedIndexChanged;

                //create HTML table wirh 2 rows
                Table table = new Table {
                    CssClass = "cartTable"
                };
                TableRow a = new TableRow();
                TableRow b = new TableRow();

                //create 6 cells for row a
                TableCell a1 = new TableCell {
                    RowSpan = 2, Width = 50
                };
                TableCell a2 = new TableCell {
                    Text = string.Format("<h4>{0}</h4><br/>{1}<br/>In Stock",
                                         room.Name, "Item No: " + room.Id),
                    HorizontalAlign = HorizontalAlign.Left, Width = 350
                };
                TableCell a3 = new TableCell {
                    Text = "Unit Price<hr />"
                };
                TableCell a4 = new TableCell {
                    Text = "Quantity<hr />"
                };
                TableCell a5 = new TableCell {
                    Text = "Items Total<hr />"
                };
                TableCell a6 = new TableCell {
                };

                //create 6 cells for row a
                TableCell b1 = new TableCell {
                };
                TableCell b2 = new TableCell {
                    Text = "$ " + room.Price
                };
                TableCell b3 = new TableCell {
                };
                TableCell b4 = new TableCell {
                    Text = "$ " + Math.Round((cart.Amount * (double)room.Price), 2)
                };
                TableCell b5 = new TableCell {
                };
                TableCell b6 = new TableCell {
                };

                //set special controls
                a1.Controls.Add(btnImage);
                a6.Controls.Add(lnkDelete);
                b3.Controls.Add(ddlAmount);

                //Add cells to rows
                a.Cells.Add(a1);
                a.Cells.Add(a2);
                a.Cells.Add(a3);
                a.Cells.Add(a4);
                a.Cells.Add(a5);
                a.Cells.Add(a6);

                b.Cells.Add(b1);
                b.Cells.Add(b2);
                b.Cells.Add(b3);
                b.Cells.Add(b4);
                b.Cells.Add(b5);
                b.Cells.Add(b6);

                //Add rows to table
                table.Rows.Add(a);
                table.Rows.Add(b);

                //Add table to pnlShoppingCart
                pnlShoppingCart.Controls.Add(table);

                //add total amount of item in cart to subtotal
                subTotal += (cart.Amount * (double)room.Price);
            }

            //add current user's shopping cart to user specific  session
            Session[User.Identity.GetUserId()] = purchaseList;
        }
 protected override void InitializeInternal()
 {
     RoomModel = new Models.RoomModel();
 }