Пример #1
0
        public ActionResult Create([Bind(Include = "FurnitureID,FurnitureName,FurnitureImg,buildLevel,furnitureType,BoardFootEst,AdditionalNotes,CompletedBefore")] Furniture furniture)
        {
            if (ModelState.IsValid)
            {
                db.FurniturePieces.Add(furniture);
                db.SaveChanges();
                return(RedirectToAction("Create", "FurnitureParts", furniture));
            }

            return(View(furniture));
        }
        public ActionResult Create(string submit, Furniture furniture, [Bind(Include = "FurniturePartId,FurnitureIndex,PartName,PartCount,Width,Length,BoardThickness,partBoardFoot,PartNotes,PartImgUrl")] FurniturePart furniturePart)
        {
            switch (submit)
            {
            case "Add Another Part":
                if (ModelState.IsValid)
                {
                    furniturePart.FurniturePieceName = furniture.FurnitureName;     //Set Name and ID for Parts DB
                    furniturePart.FurnitureIndex     = furniture.FurnitureID;
                    furniturePart.partBoardFoot      = 0;
                    double BoardFoot = furniturePart.PartCount * ((furniturePart.Width * furniturePart.Length * furniturePart.BoardThickness) / 144);
                    BoardFoot = Math.Round(BoardFoot, 4);
                    furniturePart.partBoardFoot = BoardFoot;
                    db.FurnitureParts.Add(furniturePart);
                    db.SaveChanges();

                    return(RedirectToAction("create", "FurnitureParts", furniture));    //Returns Furniture for ID and Name
                }
                break;

            case "Finished":
                if (ModelState.IsValid)
                {
                    furniturePart.FurniturePieceName = furniture.FurnitureName;
                    furniturePart.FurnitureIndex     = furniture.FurnitureID;
                    double BoardFoot = furniturePart.PartCount * ((furniturePart.Width * furniturePart.Length * furniturePart.BoardThickness) / 144);
                    BoardFoot = Math.Round(BoardFoot, 4);
                    furniturePart.partBoardFoot = BoardFoot;
                    db.FurnitureParts.Add(furniturePart);
                    db.SaveChanges();
                    var id = furniturePart.FurnitureIndex;                         //FurnitureID = FurnitureIndex
                    return(RedirectToAction("Details", "Furnitures", new { id })); //Back to Furniture Details View
                }
                break;

            case "Cancel":
            {
                return(RedirectToAction("Index", "furnitures"));
            }

            default:
                break;
            }

            return(View(furniturePart));
        }