Пример #1
0
        public static int DisplayAddShape()
        {
            var validationService = new ShapeValidationService();
            var mainService       = new MainService();
            int userInput         = 0;

            do
            {
                Console.Clear();
                Console.WriteLine("New Shape ");
                Console.WriteLine();
                Console.WriteLine("Type the shape information");
                var result = Console.ReadLine();
                try
                {
                    if (result.ToLower().Trim().Equals("exit"))
                    {
                        DisplayMainMenu();
                    }
                    if (result.ToLower().Trim().Equals("help"))
                    {
                        DisplayHelp();
                    }
                    if (result.ToLower().Contains("circle"))
                    {
                        #region circleCodeRegion
                        var validationResponse = validationService.CircleValidation(result);
                        if (validationResponse.Acknowledge != AcknowledgeType.Failure)
                        {
                            var addingResponse =
                                mainService.AddShape(new ShapeRequest()
                            {
                                ShapeDto = validationResponse.ShapeDto,
                                Area     = validationResponse.Area
                            });
                            Console.WriteLine("");
                            Console.WriteLine(">> Shape id " + addingResponse.ShapeId + ": Circle with centre at (" + validationResponse.ShapeArray[1] + ", " + validationResponse.ShapeArray[2] + ") and radius " + validationResponse.ShapeArray[3]);
                            Console.WriteLine(">> Area: " + validationResponse.Area);
                            Console.ReadKey();
                        }
                        else
                        {
                            Console.WriteLine("");
                            Console.WriteLine(validationResponse.Message);
                            Console.WriteLine("Press any key to try again...");
                            Console.ReadKey();
                        }
                        #endregion
                    }
                    if (result.ToLower().Contains("square"))
                    {
                        #region SquareRegion
                        var validationResponse = validationService.SquareValidation(result);
                        if (validationResponse.Acknowledge != AcknowledgeType.Failure)
                        {
                            var addingResponse =
                                mainService.AddShape(new ShapeRequest()
                            {
                                ShapeDto = validationResponse.ShapeDto,
                                Area     = validationResponse.Area
                            });
                            Console.WriteLine("");
                            Console.WriteLine(">> Shape id " + addingResponse.ShapeId + ": Square with centre at (" + validationResponse.ShapeArray[1] + ", " + validationResponse.ShapeArray[2] + ") and side length  " + validationResponse.ShapeArray[3]);
                            Console.WriteLine(">> Area: " + validationResponse.Area);
                            Console.ReadKey();
                        }
                        else
                        {
                            Console.WriteLine("");
                            Console.WriteLine(validationResponse.Message);
                            Console.WriteLine("Press any key to try again...");
                            Console.ReadKey();
                        }
                        #endregion
                    }
                    if (result.ToLower().Contains("rectangle"))
                    {
                        #region rectangleCodeRegion
                        var validationResponse = validationService.RectangleValidation(result);
                        if (validationResponse.Acknowledge != AcknowledgeType.Failure)
                        {
                            var addingResponse =
                                mainService.AddShape(new ShapeRequest()
                            {
                                ShapeDto = validationResponse.ShapeDto,
                                Area     = validationResponse.Area
                            });
                            Console.WriteLine("");
                            Console.WriteLine(">> Shape id " + addingResponse.ShapeId + ": Rectangle with centre at (" + validationResponse.ShapeArray[1] + ", " + validationResponse.ShapeArray[2] + ") and side1: " + validationResponse.ShapeArray[3] + " side2: " + validationResponse.ShapeArray[4]);
                            Console.WriteLine(">> Area: " + validationResponse.Area);
                            Console.ReadKey();
                        }
                        else
                        {
                            Console.WriteLine("");
                            Console.WriteLine(validationResponse.Message);
                            Console.WriteLine("Press any key to try again...");
                            Console.ReadKey();
                        }
                        #endregion
                    }
                    if (result.ToLower().Contains("triangle"))
                    {
                        #region triangleCodeRegion
                        var validationResponse = validationService.TriangleValidation(result);
                        if (validationResponse.Acknowledge != AcknowledgeType.Failure)
                        {
                            var addingResponse =
                                mainService.AddShape(new ShapeRequest()
                            {
                                ShapeDto = validationResponse.ShapeDto,
                                Area     = validationResponse.Area
                            });
                            Console.WriteLine("");
                            Console.WriteLine(">> Shape id " + addingResponse.ShapeId + ": Triangle with centre at (" + validationResponse.ShapeArray[1] + ", " + validationResponse.ShapeArray[2] + ") and vertice1: " + validationResponse.ShapeArray[3] + " vertice2: " + validationResponse.ShapeArray[4] + " vertice2: " + validationResponse.ShapeArray[5]);
                            Console.WriteLine(">> Area: " + validationResponse.Area);
                            Console.ReadKey();
                        }
                        else
                        {
                            Console.WriteLine("");
                            Console.WriteLine(validationResponse.Message);
                            Console.WriteLine("Press any key to try again...");
                            Console.ReadKey();
                        }
                        #endregion
                    }
                    if (result.ToLower().Contains("donut"))
                    {
                        #region donutCodeRegion
                        var validationResponse = validationService.DonutValidation(result);
                        if (validationResponse.Acknowledge != AcknowledgeType.Failure)
                        {
                            var addingResponse =
                                mainService.AddShape(new ShapeRequest()
                            {
                                ShapeDto = validationResponse.ShapeDto,
                                Area     = validationResponse.Area
                            });
                            Console.WriteLine("");
                            Console.WriteLine(">> Shape id " + addingResponse.ShapeId + ": Donut with centre at (" + validationResponse.ShapeArray[1] + ", " + validationResponse.ShapeArray[2] + ") and radius1: " + validationResponse.ShapeArray[3] + " radius2: " + validationResponse.ShapeArray[4]);
                            Console.WriteLine(">> Area: " + validationResponse.Area);
                            Console.ReadKey();
                        }
                        else
                        {
                            Console.WriteLine("");
                            Console.WriteLine(validationResponse.Message);
                            Console.WriteLine("Press any key to try again...");
                            Console.ReadKey();
                        }
                        #endregion
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Wrong Option");
                }
            } while (userInput != 1);
            return(4);
        }