コード例 #1
0
        public TimeTableIndexViewModel GetModelWIthoutRoutes(int?id)
        {
            var line = this.Db.Lines
                       .Where(x => x.Id == id)
                       .Include(x => x.Routes)
                       .FirstOrDefault();

            if (line == null)
            {
                return(null);
            }

            var createRouteModel = new CreateRouteInputModel
            {
                LineId = id.Value
            };

            var model = new TimeTableIndexViewModel
            {
                CreateRoute = createRouteModel
            };

            if (!line.Routes.Any())
            {
                model.HasRoutes = default(bool);
                model.Tab       = "1";
            }
            else
            {
                model.HasRoutes = true;
            }

            return(model);
        }
コード例 #2
0
        public IActionResult Create
            ([Bind(Prefix = nameof(TimeTableIndexViewModel.CreateRoute))] CreateRouteInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(TimeTableController.Index), "TimeTable", new { id = model.LineId }));
            }

            var result = this.RouteService.CreateRoute(model);

            if (!result.HasError)
            {
                this.TempData.Put(MessageConstants.Name, new MessageModel
                {
                    Type    = MessageType.Success,
                    Message = result.Message
                });
            }
            else
            {
                this.TempData.Put(MessageConstants.Name, new MessageModel
                {
                    Type    = MessageType.Danger,
                    Message = result.Message
                });
            }

            return(RedirectToAction(nameof(TimeTableController.Index), "TimeTable", new { id = model.LineId }));
        }
コード例 #3
0
        public BaseModel CreateRoute(CreateRouteInputModel model)
        {
            if (!Enum.TryParse(model.Direction, out Direction directionType))
            {
                this.BaseModel.HasError = true;
                this.BaseModel.Message  = MessageConstants.InvalidDirectionType;
                return(this.BaseModel);
            }

            if (!Enum.TryParse(model.Day, out DayType dayType))
            {
                this.BaseModel.HasError = true;
                this.BaseModel.Message  = MessageConstants.InvalidDayType;
                return(this.BaseModel);
            }

            var anyRouteName = this.Db.Routes
                               .Any(x => x.LineId == model.LineId &&
                                    x.RouteName == model.RouteName &&
                                    x.Direction == directionType &&
                                    x.DayType == dayType);

            if (anyRouteName)
            {
                this.BaseModel.HasError = true;
                this.BaseModel.Message  = string.Format(MessageConstants.HaveRouteName, model.RouteName);
                return(this.BaseModel);
            }

            var route = new Route
            {
                RouteName = model.RouteName,
                Direction = directionType,
                DayType   = dayType,
                LineId    = model.LineId
            };

            try
            {
                this.Db.Routes.Add(route);
                this.Db.SaveChanges();

                this.BaseModel.HasError = false;
                this.BaseModel.Message  = MessageConstants.CreateRoute;
            }
            catch (Exception)
            {
                this.BaseModel.HasError = true;
                this.BaseModel.Message  = MessageConstants.NoCreateRoute;
            }

            return(this.BaseModel);
        }
コード例 #4
0
        public async Task <IActionResult> Create(CreateRouteInputModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string routeId = await this.routeService.CreateAsync(model.Title, CurrentUser);

                    if (string.IsNullOrEmpty(routeId))
                    {
                        AddDangerNotification(string.Format(Notifications.CreatedFail, model.Title));
                        return(Redirect("/Routes"));
                    }

                    logger.LogInformation(
                        string.Format(SetLog.CreatedSuccess,
                                      CurrentUser.UserName,
                                      CurrentController,
                                      routeId
                                      ));

                    AddWarningNotification(string.Format(Notifications.CreatedSuccess, model.Title));

                    return(Redirect($"/Routes/Update/{routeId}"));
                }
                else
                {
                    logger.LogInformation(string.Format(SetLog.CreatedFail,
                                                        CurrentUser.UserName,
                                                        CurrentController));

                    AddDangerNotification(string.Format(Notifications.CreatedFail, model.Title));
                    return(View(model));
                }
            }
            catch (System.Exception e)
            {
                logger.LogError(string.Format(SetLog.Error,
                                              CurrentUser.UserName,
                                              CurrentController,
                                              e.Message));

                AddDangerNotification(string.Format(Notifications.Fail));

                return(Redirect("/Routes"));
            }
        }
コード例 #5
0
        public IViewComponentResult Invoke()
        {
            var model = new CreateRouteInputModel();

            return(View(model));
        }