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)); }
public DB.City ToDBCity() { DB.City city = new DB.City(); city.Name = Name; return(city); }
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)); }
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(); } }