예제 #1
0
        private async void AddToHistory(City currentCity)
        {
            foreach (City city in CitiesHistory)
            {
                if (city.id.Equals(currentCity.id))
                {
                    CitiesHistory.Remove(city);
                    break;
                }
            }

            if (CitiesHistory.Count == 10)
            {
                CitiesHistory.RemoveAt(9);
            }
            CitiesHistory.Insert(0, currentCity);

            //Sledeci deo koda update-uje history prozor

            string        path        = Directory.GetParent(Directory.GetParent(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).FullName).FullName;
            List <string> temperature = new List <string>();

            foreach (City city in CitiesHistory)
            {
                var product1 = await GetFiveDayAsync(apiFiveDayUrl + city.name + "," + city.country + apiAppId);

                string temperatura = Math.Floor(product1.list[dayComparison].main.temp_min - 272.15) + "/" + Math.Floor(product1.list[dayComparison].main.temp_max - 272.15) + "°C";
                temperature.Add(temperatura);
            }
            history_window.update(temperature);
        }
예제 #2
0
        public int Redone(int current, DateTime time)
        {
            int step = current;

            try
            {
                step--;

                List <CitiesHistory> history;

                using (LibContext context = new LibContext())
                {
                    history = context.CitiesHistory.Where(c => c.OperationDate <= time).ToList();
                    history.Reverse();
                    GenericRepository <Cities> generic = new GenericRepository <Cities>(context);

                    if (step < history.Count && step >= 0)
                    {
                        CitiesHistory pacient   = history[step];
                        string        operation = pacient.Operation;

                        context.Database.ExecuteSqlCommand("DISABLE TRIGGER CitiesHistory ON Cities");
                        context.Database.ExecuteSqlCommand("DISABLE TRIGGER CitiesInsert ON Cities");

                        if (operation == "inserted")
                        {
                            Cities entity = new Cities
                            {
                                Id   = pacient.Id,
                                Name = pacient.CurrentName
                            };

                            using (var scope = context.Database.BeginTransaction())
                            {
                                context.Cities.Add(entity);
                                context.SaveChanges();
                                scope.Commit();
                            }
                        }
                        else if (operation == "updated")
                        {
                            Cities entity = generic.Get(c => c.Id == pacient.Id).FirstOrDefault();
                            if (entity != null)
                            {
                                entity.Name = pacient.CurrentName;

                                generic.Update(entity);
                            }
                        }
                        else if (operation == "deleted")
                        {
                            Cities entity = generic.Get(c => c.Id == pacient.Id).FirstOrDefault();
                            if (entity != null)
                            {
                                generic.Remove(entity);
                            }
                        }

                        context.Database.ExecuteSqlCommand("ENABLE TRIGGER CitiesHistory ON Cities");
                        context.Database.ExecuteSqlCommand("ENABLE TRIGGER CitiesInsert ON Cities");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(step);
        }