示例#1
0
        public ActionResult Create(Station station)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (!User.IsInRole("Admin"))
            {
                station.OwnerId = User.Identity.GetUserId();
            }

            if (ModelState.IsValid)
            {
                if (ValidateStation.AlreadyExistsStation(station))
                {
                    ModelState.AddModelError(string.Empty, "A estação já existe na base de dados.");

                    StationViewModel viewModel = new StationViewModel(db);
                    viewModel.Name      = station.Name;
                    ViewBag.ListRegions = ListRegionsById.createListItems(db, station.RegionId);
                    return(View(viewModel));
                }

                db.Stations.Add(station);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(new StationViewModel(db)));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, StationViewModel stationViewModel)
        {
            if (ModelState.IsValid)
            {
                string path = stationViewModel.LogoPath;

                if (stationViewModel.LogoFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(stationViewModel.LogoFile, "Stations");
                }

                StationEntity stationEntity = _converterHelper.ToStationEntity(stationViewModel, path, false);
                _context.Update(stationEntity);
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("updating"))
                    {
                        ModelState.AddModelError(string.Empty, $"Already exists a Station {stationEntity.Name}. ");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }
            return(View(stationViewModel));
        }
示例#3
0
        public IHttpActionResult AddStation(StationViewModel model)
        {
            try
            {
                Station station = new Station();

                station.Address   = model.Address;
                station.Latitude  = model.Latitude;
                station.Longitude = model.Longitude;
                station.Name      = model.Name;

                if (model.NLine == null)
                {
                    model.NLine = new List <int>();
                }

                foreach (var line in model.NLine)
                {
                    station.NLine.Add(UnitOfWork.NetworkLines.Find(x => x.LineNumber == line).First());
                    var networkline = UnitOfWork.NetworkLines.Find(x => x.LineNumber == line).First();
                    networkline.Stations.Add(station);
                    UnitOfWork.NetworkLines.Update(networkline);
                }
                UnitOfWork.Stations.Add(station);
                UnitOfWork.Complete();
                return(Ok($"Station {model.Name} successfully added."));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#4
0
        public async Task <IActionResult> Create(StationViewModel stationViewModel)
        {
            if (ModelState.IsValid)
            {
                string path = string.Empty;

                if (stationViewModel.LogoFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(stationViewModel.LogoFile, "Stations");
                }

                StationEntity team = _converterHelper.ToStationEntity(stationViewModel, path, true);
                _context.Add(team);

                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "Already there is a record with the same name.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }

            return(View(stationViewModel));
        }
示例#5
0
        private Station AdaptStation(StationViewModel model)
        {
            Station s = UnitOfWork.Stations.Get(model.Id);

            s.Name      = model.Name;
            s.Address   = model.Address;
            s.Latitude  = model.Latitude;
            s.Longitude = model.Longitude;
            int cnt = s.NLine.Count;

            for (int i = 0; i < cnt; i++)
            {
                var line = s.NLine.ToList()[0];
                line.Stations.Remove(s);
                s.NLine.Remove(line);
            }
            UnitOfWork.Complete();

            foreach (var node in model.NLine)
            {
                s.NLine.Add(UnitOfWork.NetworkLines.Find(x => x.LineNumber == node).First());
                UnitOfWork.NetworkLines.Find(x => x.LineNumber == node).First().Stations.Add(s);
            }
            return(s);
        }
        private async void ComboBox_Loaded(object sender, RoutedEventArgs e)
        {
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }
            comboBox.Text      = "正在加载城市数据";
            comboBox.IsEnabled = false;
            StationDataInterpreter sdi = new StationDataInterpreter();
            var isSync = await sdi.IsCreateAsync();

            if (isSync)
            {
                await sdi.ExecuteSyncAsync();

                await sdi.CreateDataAsync();
            }
            await Task.Run(() =>
            {
                _viewModel = new StationViewModel();
            });

            comboBox.Text      = "";
            this.DataContext   = _viewModel;
            comboBox.IsEnabled = true;
        }
示例#7
0
 private void Devices_Loaded(object sender, RoutedEventArgs e)
 {
     ViewModel        = new StationViewModel();
     ViewModel.light  = light;
     ViewModel.blinds = blinds;
     ViewModel.air    = air;
     Bindings.Update();
 }
示例#8
0
        public ActionResult EditStation(StationViewModel stationView)
        {
            var mapper     = new MapperConfiguration(cfg => cfg.CreateMap <StationViewModel, StationDTO>()).CreateMapper();
            var stationDto = mapper.Map <StationViewModel, StationDTO>(stationView);

            _stationService.EditStation(stationDto);
            return(RedirectToAction("ShowStations"));
        }
        private void SetupStationBreadcrumb(StationViewModel station)
        {
            var navigateToAdminStation = new AsyncCommand((obj) =>
            {
                Navigator.Navigate(Shared.Navigation.NavigationType.AdminStations, station.Model.Id);
            });

            this.Crumbs.Add(new BreadcrumbItemModel(station.Name, navigateToAdminStation));
        }
示例#10
0
        public async Task <ObservableCollection <StationViewModel> > GetAllStationsAsync()
        {
            var items = await StationDatabase.GetInstance.GetItemsAsync();

            ObservableCollection <Station>          allStations = new ObservableCollection <Station>(items);
            ObservableCollection <StationViewModel> stationList = new ObservableCollection <StationViewModel>();

            char[] criteria = new char[2];

            // Filter from settings
            if (SystemSettings.MetroVisible)
            {
                criteria[0] = 'U';
            }

            if (SystemSettings.STrainVisible)
            {
                criteria[1] = 'S';
            }

            // loop filters merged stations for U and S lines
            foreach (Station station in allStations)
            {
                bool   final       = false;
                String imageSource = String.Empty;

                // check which icon is used
                if (station.Lines.IndexOf(criteria[0]) >= 0 &&
                    station.Lines.IndexOf(criteria[1]) >= 0)
                {
                    final       = true;
                    imageSource = "merged.png";
                }
                else if (station.Lines.IndexOf(criteria[0]) >= 0)
                {
                    final       = true;
                    imageSource = "metro.png";
                }
                else if (station.Lines.IndexOf(criteria[1]) >= 0)
                {
                    final       = true;
                    imageSource = "strain.png";
                }

                if (final)
                {
                    StationViewModel viewModel = new StationViewModel(station);
                    viewModel.ImageSource = imageSource;
                    stationList.Add(viewModel);
                }
            }

            return(stationList);
        }
示例#11
0
        public async Task <IActionResult> Create([Bind("Id,Name,EcpCode,Description")] StationViewModel stationViewModel)
        {
            if (ModelState.IsValid)
            {
                var stationDto = _mapper.Map <StationDto>(stationViewModel);
                await _stationDtoAcessLayer.AddNewStation(stationDto, "Ћенинградский");

                return(RedirectToAction("Index"));
            }
            return(View(stationViewModel));
        }
示例#12
0
        public ActionResult Stations()
        {
            var stationViewModel = new StationViewModel()
            {
                Configurator = new Configurator <Station, Station>()
                               .Configure()
                               .Url(Url.Action(nameof(HandleStations)))
            };

            return(View(stationViewModel));
        }
示例#13
0
        public ActionResult Create()
        {
            var              company   = db.Employees.Find(User.Identity.GetUserId()).Company;
            Station          station   = new Station();
            StationViewModel viewModel = new StationViewModel()
            {
                _Station = station, CompanyName = company.Name
            };

            return(View(viewModel));
        }
示例#14
0
 public StationEntity ToStationEntity(StationViewModel model, string path, bool isNew)
 {
     return(new StationEntity
     {
         Id = isNew ? 0 : model.Id,
         LogoPath = path,
         Name = model.Name,
         Address = model.Address,
         LegalCertificate = model.LegalCertificate,
         LegalName = model.LegalName
     });
 }
        private void Devices_Loaded(object sender, RoutedEventArgs e)
        {
            ViewModel = new StationViewModel();
            ViewModel.AddModule(light);
            ViewModel.AddModule(blinds);
            ViewModel.AddModule(air);

            ViewModel.ligsens = ligsens;
            ViewModel.term    = term;
            ViewModel.air     = air;
            Bindings.Update();
        }
示例#16
0
 public IHttpActionResult UpdateStation(StationViewModel model)
 {
     try
     {
         UnitOfWork.Stations.Update(AdaptStation(model));
         UnitOfWork.Complete();
         return(Ok($"Station {model.Name} successfully updated."));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
示例#17
0
        public ActionResult Edit(StationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = _iStationEntityRepos.FindById(model.StationId);

                Mapper.Map(model, result);
                result.TeamEntities = _iTeamEntityRepos.FindById(model.TeamEntityId);
                _iStationEntityRepos.SetModified(result);
                _iStationEntityRepos.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
示例#18
0
        public IEnumerable <StationDetailViewModel> StationListToViewModelList(IEnumerable <Station> stations)
        {
            StationViewModel stationViewModel = new StationViewModel
            {
                Stations = new List <StationDetailViewModel>()
            };

            foreach (Station station in stations)
            {
                stationViewModel.Stations.Add(StationToViewModel(station));
            }

            return(stationViewModel.Stations);
        }
        public StationView(SystemInterface systemInterface)
        {
            InitializeComponent();

            listStations.ItemTapped += OnTapEventAsync;

            viewModel = new StationViewModel(systemInterface);

            viewModel.GetStations();

            BindingContext = viewModel;

            _systemInterface = systemInterface;
        }
示例#20
0
        public IActionResult Index()
        {
            List <Station>   stations = repo.GetAllStations();
            StationViewModel vm       = new StationViewModel
            {
                Stations = new List <StationDetailViewModel>()
            };

            foreach (Station station in stations)
            {
                vm.Stations.Add(converter.StationToViewModel(station));
            }

            return(View(vm.Stations));
        }
示例#21
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,EcpCode,Description")] StationViewModel stationViewModel)
        {
            if (id != stationViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var stationDto = _mapper.Map <StationDto>(stationViewModel);
                var result     = await _stationDtoAcessLayer.EditStation(stationDto);

                return(result ? RedirectToAction("Index") : null); //TODO: null заменить на страницу с ошибками.
            }
            return(View(stationViewModel));
        }
示例#22
0
 public ActionResult CreateStation(StationViewModel station)
 {
     try
     {
         var stationDto = new StationDTO {
             Name = station.Name, Locality = station.Locality, Description = station.Description
         };
         _stationService.MakeStation(stationDto);
         return(Content("Вы успешно создали станцию"));
     }
     catch (ValidationException ex)
     {
         ModelState.AddModelError(ex.Property, ex.Message);
     }
     return(View(station));
 }
示例#23
0
        // GET: Stations/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            StationEntity stationEntity = await _context.Stations.FindAsync(id);

            if (stationEntity == null)
            {
                return(NotFound());
            }
            StationViewModel stationViewModel = _converterHelper.ToStationViewModel(stationEntity);

            return(View(stationViewModel));
        }
        public List <StationViewModel> GetStationDetails()
        {
            FreeWheelDBEntities     context = new FreeWheelDBEntities();
            List <StationViewModel> result  = new List <StationViewModel>();

            var obj = context.STATIONs.Select(u => u).ToList();

            if (obj != null && obj.Count() > 0)
            {
                foreach (var data in obj)
                {
                    StationViewModel model = new StationViewModel();
                    model.statinId    = data.STATION_ID;
                    model.stationName = data.STATION_NAME;
                    result.Add(model);
                }
            }
            return(result);
        }
示例#25
0
            public void LoadCellValues(StationViewModel station)
            {
                ExceptionUtility.Try(() =>
                {
                    this._station = station;

                    if (station.Running)
                    {
                        this.SetLine1Font(BoldCellTextFont);
                        this._checkbox.Hidden = true;
                    }
                    else
                    {
                        this.SetLine1Font(NormalCellTextFont);
                        this._checkbox.Hidden = false;
                    }

                    this.LoadCellValues(station.Id, station.Name, station.Description);
                    _checkbox.SetChecked(station.Selected);

                    if (station.ZoneColor == null)
                    {
                        _colorView.BackgroundColor = UIColor.White;
                    }
                    else
                    {
                        _colorView.BackgroundColor = Colors.FromHex(station.ZoneColor.Value);
                    }

                    if (station.Running)
                    {
                        this.SetStatus(StringLiterals.Running.ToUpper());
                    }
                    else if (station.Starting) //TODO: replace with IsUpdatingStatus
                    {
                        this.SetStatus(StringLiterals.Starting.ToUpper());
                    }
                    else
                    {
                        this.SetStatus(null);
                    }
                });
            }
示例#26
0
        public static StationViewModel CreateModel(this Station station)
        {
            var model = new StationViewModel();

            model.StationID = station.StationID;
            model.Name      = station.Name;
            if (station.Available != null)
            {
                model.Available = (bool)station.Available;
            }
            else
            {
                model.Available = false;
            }
            model.Location    = station.Location;
            model.LastCheckIn = station.LastCheckIn;
            model.Status      = station.Status;
            model.IsOnline    = station.LastCheckIn >= DateTime.Now.AddSeconds(-10);
            return(model);
        }
示例#27
0
        // GET: Stations/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var stationViewModel = new StationViewModel
            {
                Station = await db.Stations.Include(s => s.StationEquipments).Include(s => s.Floor).FirstOrDefaultAsync(s => s.ID == id)
            };

            if (stationViewModel.Station == null)
            {
                return(NotFound());
            }

            var allEquipmentList = db.Equipment.ToListAsync();
            var allTypesList     = db.WorkStyles.ToListAsync();
            var allFloorsList    = db.Floors.ToListAsync();

            stationViewModel.AllEquipment = (await allEquipmentList).Select(o => new SelectListItem
            {
                Text  = o.Name,
                Value = o.ID.ToString()
            });

            stationViewModel.AllWorkStyles = (await allTypesList).Select(w => new SelectListItem
            {
                Text  = w.Name,
                Value = w.ID.ToString()
            });

            stationViewModel.AllFloors = (await allFloorsList).OrderBy(f => f.SortName).Select(f => new SelectListItem
            {
                Text  = f.Name,
                Value = f.ID.ToString()
            });

            return(View(stationViewModel));
        }
示例#28
0
        private void SetUp()
        {
            var Data = new StationViewModel(SimulationModel);

            View = new StationView
            {
                DataContext = Data
            };
            pickService = new DefaultPickService(simulationService);

            if (isLocked)
            {
                Lock();
            }
            else
            {
                Unlock();
            }

            Views.Add(View);
            Stations.Add(this);
        }
示例#29
0
        private static StationViewModel AdaptStationViewModel(Station station)
        {
            StationViewModel model = new StationViewModel();

            model.Name      = station.Name;
            model.Longitude = station.Longitude;
            model.Latitude  = station.Latitude;
            model.Address   = station.Address;
            model.Id        = station.Id;

            if (station.NLine == null)
            {
                station.NLine = new List <NetworkLine>();
            }

            foreach (var line in station.NLine)
            {
                model.NLine.Add(line.LineNumber);
            }

            return(model);
        }
示例#30
0
        public ActionResult Create(StationViewModel viewModel)
        {
            var user = db.Employees.Find(User.Identity.GetUserId());

            viewModel._Station.CompanyId = user.CompanyId;

            if (ModelState.IsValid)
            {
                db.Stations.Add(viewModel._Station);

                foreach (var price in ScheduleGenerator.GeneratePrices(Double.Parse(viewModel.NormalCost), Double.Parse(viewModel.FastCost)))
                {
                    price.StationId = viewModel._Station.Id;
                    db.Prices.Add(price);
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
示例#31
0
        private void btnIRISDemo_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                var dialog = new Stations();

                System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(dialog);
                helper.Owner = (IntPtr)ThisAddIn.ExcelApplication.Hwnd;

                StationViewModel viewModel = new StationViewModel();

                viewModel.RequestClose += new EventHandler(dialog.OnRequestClose);
                dialog.DataContext = viewModel;
                dialog.ShowDialog();

                viewModel.RequestClose -= new EventHandler(dialog.OnRequestClose);
                dialog.Close();
            }
            catch (CustomException ex)
            {
                Ribbon.ShowError(ex.HasCustomMessage ? ex.Message : Resources.LayerOperationError);
            }
            catch (Exception exception)
            {
                Logger.LogException(exception);
                Ribbon.ShowError(Resources.DefaultErrorMessage);
            }
        }
        internal void GetStationData(StationViewModel selectedViewModel)
        {
            StationDataModel model = selectedViewModel.StationData;

            StringBuilder sb = BuildQuery(model);

            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(new Uri(sb.ToString()));
            myRequest.UserAgent = "Mozilla/4.0+";

            XDocument ResponseText;
            using (HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    ResponseText = XDocument.Load(responseStream);
                }
            }

            string data = GetDatafromFeed(ResponseText.ToString());

            _Worksheet workSheet = GetActiveWorksheet();

            // Gets the range from the excel for data row and columns
            Range currentRange = workSheet.GetRange(Globals.ThisAddIn.Application.ActiveCell, rowCount, columnCount);
            if (currentRange != null)
            {
                currentRange.Select();
                currentRange.Value2 = tempValue;
            }

            WorkflowController.Instance.CreateLayerMap();
        }