コード例 #1
0
        public async Task <ServiceResponse <string> > AddLine(AddLineDTO newLine)
        {
            ServiceResponse <string> response = new ServiceResponse <string>();

            Enums.LineType    type   = (Enums.LineType)Enum.Parse(typeof(Enums.LineType), newLine.Type);
            List <Coordinate> coords = new List <Coordinate>();

            try
            {
                Line line = new Line {
                    Name = newLine.Name, Type = type
                };
                await _context.Lines.AddAsync(line);

                await _context.SaveChangesAsync();

                foreach (CoordinateDTO coord in newLine.Coordinates)
                {
                    coords.Add(new Coordinate {
                        LineId = line.Id, XCoordinate = coord.XCoordinate, YCoordinate = coord.YCoordinate
                    });
                }
                await _context.Coordinates.AddRangeAsync(coords);

                await _context.SaveChangesAsync();

                response.Data = line.Name;
            }
            catch (Exception e)
            {
                response.Success = false;
                response.Message = e.Message;
            }
            return(response);
        }
コード例 #2
0
        public async Task <IActionResult> AddLine(AddLineDTO request)
        {
            ServiceResponse <string> response = await _routeService.AddLine(request);

            if (!response.Success)
            {
                return(BadRequest(response));
            }
            return(Ok(response));
        }