예제 #1
0
        public IActionResult CreateShelf(Shelf shelf)
        {
            var standShelfSize = ctx.GetStandardShellSize(1);

            if (ModelState.IsValid)
            {
                bool shelfIdExist = ctx.ShelfExists(shelf.ShelfId);
                if (!shelfIdExist)
                {
                    if ((ctx.DuplicateCoorXId(shelf.ShelfId, shelf.CoorX) && ctx.DuplicateCoorYId(shelf.ShelfId, shelf.CoorY)) ||
                        (ctx.DuplicateCoorXExceptId(shelf.ShelfId, shelf.CoorX) && ctx.DuplicateCoorYExceptId(shelf.ShelfId, shelf.CoorY)))
                    {
                        ViewBag.DuplicateCoordinate = "Coordinate [X,Y] is already existed !!!";
                        ViewBag.StandardSize        = new StandardSize
                        {
                            StandardFloor = standShelfSize.StandardFloor,
                            StandardCell  = standShelfSize.StandardCell
                        };
                        return(View(shelf));
                    }
                    else
                    {
                        ViewBag.StandardSize = new StandardSize
                        {
                            StandardFloor = standShelfSize.StandardFloor,
                            StandardCell  = standShelfSize.StandardCell
                        };
                        shelf.Status = true;
                        ctx.AddShelf(shelf);

                        for (int i = 1; i <= shelf.FloorNumber; i++)
                        {
                            Floor floor = new Floor
                            {
                                FloorId = $"{shelf.ShelfId}-{i}",
                                ShelfId = shelf.ShelfId
                            };
                            floor.Status = true;
                            ctx.AddFloor(floor);
                        }
                        ;
                        for (int i = 1; i <= shelf.FloorNumber; i++)
                        {
                            for (int j = 1; j <= shelf.CellNumber; j++)
                            {
                                Cell cell = new Cell
                                {
                                    CellId  = $"{shelf.ShelfId}-{i}-{j}",
                                    FloorId = $"{shelf.ShelfId}-{i}"
                                };
                                cell.Status = true;
                                ctx.AddCell(cell);
                            }
                        }
                        ;
                        return(RedirectToAction(nameof(ListAllShelf)));
                    }
                }
                else
                {
                    ViewBag.ShelfExistError = "Shelf Id is already existed !!!";
                    ViewBag.StandardSize    = new StandardSize
                    {
                        StandardFloor = standShelfSize.StandardFloor,
                        StandardCell  = standShelfSize.StandardCell
                    };
                    return(View(shelf));
                }
            }
            ViewBag.StandardSize = new StandardSize
            {
                StandardFloor = standShelfSize.StandardFloor,
                StandardCell  = standShelfSize.StandardCell
            };
            return(View(shelf));
        }