Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PutCity(int id, EasyCity city)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DB.City cityDb = city.ToDBCity();
            cityDb.Id = id;

            db.Entry(cityDb).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public DB.City ToDBCity()
        {
            DB.City city = new DB.City();

            city.Name = Name;

            return(city);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PostCity([FromBody] EasyCity city)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.City.Add(city.ToDBCity());
            await db.SaveChangesAsync();

            DB.City cityDb = db.City.Where(n => n.Name == city.Name).FirstOrDefault();

            return(CreatedAtRoute("DefaultApi", new { id = cityDb.Id }, cityDb));
        }
Ejemplo n.º 4
0
        public void WriteToXls(DB.City city)
        {
            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2013;
                IWorkbook  workbook  = application.Workbooks.Create(1);
                IWorksheet worksheet = workbook.Worksheets[0];

                //Import the data to worksheet
                IList <DB.AQData> reports = _storage.GetDataByCity(city);
                worksheet.ImportData(reports, 2, 1, true);

                //Saving the workbook as stream
                FileStream stream = new FileStream("ImportFromDT.xlsx", FileMode.Create, FileAccess.ReadWrite);
                workbook.SaveAs(stream);
                stream.Dispose();
            }
        }