コード例 #1
0
        public ActionResult CreateReport(ReportDto report)
        {
            string token = HttpContext.Request.Headers["token"];

            if (token != TokenEmulator)
            {
                return(Unauthorized());
            }
            if (report == null)
            {
                return(BadRequest());
            }
            _reports.AddReport(DtoConverter.ConvertDtoToReport(report));
            return(Ok());
        }
コード例 #2
0
        public string LoadXmlToBase()
        {
            if (uploadFile == null || uploadFile.Length == 0)
            {
                return("Файл не выбран");
            }

            var fileExtention = Path.GetExtension(uploadFile.FileName);

            if (fileExtention != ".xml")
            {
                return("Выбранный файл не Xml");
            }

            var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "temp", uploadFile.FileName);

            var fff = Directory.GetCurrentDirectory() + "\\wwwroot";

            Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\wwwroot\\temp");

            using (var stream = new FileStream(path, FileMode.Create))
            {
                uploadFile.CopyTo(stream);
            }

            var tuple = GetItemsCollection(path);

            housesCollXml = tuple.Item1;
            plantsCollXml = tuple.Item2;

            ClearDb();

            Collection <Weather> weathersColl = new Collection <Weather>();
            IAddItemToBase <Collection <Weather> > weathers = new WeathersRepository(appDbContext);

            Collection <Consumer> housesColl = new Collection <Consumer>();
            IAddItemToBase <Collection <Consumer> > houses = new ConsumersRepository(appDbContext);

            Collection <House> dateCollection = new Collection <House>();
            IAddItemToBase <Collection <House> > dateToBase = new DatesRepository(appDbContext);

            Collection <House> houseConsCollection             = new Collection <House>();
            IAddItemToBase <Collection <House> > housesConsums = new HousesConsumptionRepository(appDbContext);

            foreach (var item in housesCollXml)
            {
                weathersColl.Add(new Weather {
                    Value = item.Weather
                });
                housesColl.Add(new Consumer {
                    Name = item.Name
                });
                dateCollection.Add(new House {
                    Date = item.Date
                });
                houseConsCollection.Add(item);
            }
            weathers.AddItem(weathersColl);
            houses.AddItem(housesColl);
            dateToBase.AddItem(dateCollection);

            Collection <Price> pricesColl = new Collection <Price>();
            IAddItemToBase <Collection <Price> > prices = new PricesRepository(appDbContext);

            Collection <Consumer> plantsColl = new Collection <Consumer>();
            IAddItemToBase <Collection <Consumer> > plants = new ConsumersRepository(appDbContext);

            Collection <Plant> plantConsCollection             = new Collection <Plant>();
            IAddItemToBase <Collection <Plant> > plantsConsums = new PlantsConsumptionRepository(appDbContext);

            foreach (var item in plantsCollXml)
            {
                pricesColl.Add(new Price {
                    Value = item.Price
                });
                plantsColl.Add(new Consumer {
                    Name = item.Name
                });
                plantConsCollection.Add(item);
            }
            prices.AddItem(pricesColl);
            plants.AddItem(plantsColl);


            ReportsRepository reports = new ReportsRepository(appDbContext);

            reports.AddReport(new Report
            {
                DateLoad = DateTime.Now,
                UserName = Environment.UserName
            });

            housesConsums.AddItem(houseConsCollection);
            plantsConsums.AddItem(plantConsCollection);

            File.Delete(path);

            return("Данные успешно загружены в БД");
        }