public async Task <IActionResult> Edit(int?id, string SortOrder, int?EgovIdFilter, string CodeFilter, string NameKKFilter, string NameRUFilter, int?ParentFilter, int?AreaTypeFilter, int?PageSize, int?Page) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.Page = Page; ViewBag.EgovIdFilter = EgovIdFilter; ViewBag.CodeFilter = CodeFilter; ViewBag.NameKKFilter = NameKKFilter; ViewBag.PaNameRUFilterge = NameRUFilter; ViewBag.ParentFilter = ParentFilter; ViewBag.AreaTypeFilter = AreaTypeFilter; CATO cato = null; HttpResponseMessage response = await _HttpApiClient.GetAsync($"api/CATO/{id.ToString()}"); if (response.IsSuccessStatusCode) { cato = await response.Content.ReadAsAsync <CATO>(); } return(View(cato)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,AB,CD,EF,HIJ,K,NameRU,NameKK")] CATO cATO) { if (id != cATO.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(cATO); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CATOExists(cATO.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(cATO)); }
public async Task <ActionResult> DeleteConfirmed(int id) { CATO cATO = await db.CATOes.FindAsync(id); db.CATOes.Remove(cATO); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,AB,CD,EF,HIJ,K,Name,NameKZ")] CATO cATO) { if (ModelState.IsValid) { db.Entry(cATO).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(cATO)); }
public async Task <IActionResult> Create([Bind("Id,AB,CD,EF,HIJ,K,NameRU,NameKK")] CATO cATO) { if (ModelState.IsValid) { _context.Add(cATO); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cATO)); }
public async Task <ActionResult> Create([Bind(Include = "Id,AB,CD,EF,HIJ,K,Name,NameKZ")] CATO cATO) { if (ModelState.IsValid) { db.CATOes.Add(cATO); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(cATO)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Code,NameKK,NameRU,Parent,AreaType,EgovId")] CATO cato, string SortOrder, int?EgovIdFilter, string CodeFilter, string NameKKFilter, string NameRUFilter, int?ParentFilter, int?AreaTypeFilter, int?PageSize, int?Page) { ViewBag.SortOrder = SortOrder; ViewBag.PageSize = PageSize; ViewBag.Page = Page; ViewBag.EgovIdFilter = EgovIdFilter; ViewBag.CodeFilter = CodeFilter; ViewBag.NameKKFilter = NameKKFilter; ViewBag.PaNameRUFilterge = NameRUFilter; ViewBag.ParentFilter = ParentFilter; ViewBag.AreaTypeFilter = AreaTypeFilter; if (id != cato.Id) { return(NotFound()); } if (ModelState.IsValid) { HttpResponseMessage response = await _HttpApiClient.PutAsJsonAsync( $"api/cato/{cato.Id}", cato); string OutputViewText = await response.Content.ReadAsStringAsync(); OutputViewText = OutputViewText.Replace("<br>", Environment.NewLine); try { response.EnsureSuccessStatusCode(); } catch { dynamic errors = JsonConvert.DeserializeObject <dynamic>(OutputViewText); foreach (Newtonsoft.Json.Linq.JProperty property in errors.Children()) { ModelState.AddModelError(property.Name, property.Value[0].ToString()); } return(View(cato)); } cato = await response.Content.ReadAsAsync <CATO>(); return(RedirectToAction(nameof(Index), new { PageSize = ViewBag.PageSize, Page = ViewBag.Page, SortOrder = ViewBag.SortOrder, EgovIdFilter = ViewBag.EgovIdFilter, CodeFilter = ViewBag.CodeFilter, NameKKFilter = ViewBag.NameKKFilter, NameRUFilter = ViewBag.NameRUFilter, ParentFilter = ViewBag.ParentFilter, AreaTypeFilter = ViewBag.AreaTypeFilter })); } return(View(cato)); }
public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CATO cATO = await db.CATOes.FindAsync(id); if (cATO == null) { return(HttpNotFound()); } return(View(cATO)); }
public async Task <IActionResult> PostCATO([FromBody] CATO cATO) { var catoes = _context.CATO.AsNoTracking().ToList(); if (_context.CATO.AsNoTracking().FirstOrDefault(c => c.ExpiredDateTime == null && c.Code == cATO.Code) != null) { ModelState.AddModelError("Code", "An object with this value already exists!"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.CATO.Add(cATO); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCATO", new { id = cATO.Id }, cATO)); }
public async Task <IActionResult> PutCATO([FromRoute] int id, [FromBody] CATO cATO) { var catoes = _context.CATO.AsNoTracking().ToList(); if (_context.CATO.AsNoTracking().FirstOrDefault(c => c.ExpiredDateTime == null && c.Code == cATO.Code && c.Id != cATO.Id) != null) { ModelState.AddModelError("Code", "An object with this value already exists!"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != cATO.Id) { return(BadRequest()); } _context.Entry(cATO).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CATOExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> ParseCATO(string Url) { try { int importedCount = 0, i = 0; if (!string.IsNullOrEmpty(Url)) { string jsontext = "[{}]"; List <CATO> catoes = new List <CATO>(); while (jsontext.Length > 2) { string url = Url; if (url.Last() == '/') { url = url.Remove(url.Length - 1, 1); } if (url.Contains("?")) { url += "&source={" + $"\"from\":{i * 10000},\"size\":10000" + "}"; } else { url += "?source={" + $"\"from\":{i * 10000},\"size\":10000" + "}"; } i++; using (var handler = new HttpClientHandler()) { handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true; using (var client = new HttpClient(handler)) { var response = client.GetAsync(url).GetAwaiter().GetResult(); response.EnsureSuccessStatusCode(); jsontext = await response.Content.ReadAsStringAsync(); } } dynamic data = JsonConvert.DeserializeObject <dynamic>(jsontext); foreach (Newtonsoft.Json.Linq.JObject jobject in data) { CATO cato = new CATO() { Code = jobject["Code"]?.ToString(), NameKK = jobject["NameKaz"]?.ToString(), NameRU = jobject["NameRus"]?.ToString(), Parent = !string.IsNullOrEmpty(jobject["Parent"]?.ToString()) ? (int?)Convert.ToInt32(jobject["Parent"]?.ToString()) : null, AreaType = !string.IsNullOrEmpty(jobject["AreaType"]?.ToString()) ? (int?)Convert.ToInt32(jobject["AreaType"]?.ToString()) : null, EgovId = !string.IsNullOrEmpty(jobject["Id"]?.ToString()) ? (int?)Convert.ToInt32(jobject["Id"]?.ToString()) : null }; catoes.Add(cato); } } // compare old and importing catoes List <CATO> catoesOld = _context.CATO.Where(c => c.ExpiredDateTime == null).ToList(); bool different = false; // old and new catoes if (catoesOld.Count() != catoes.Count()) { different = true; } else { catoesOld = catoesOld.Select(c => { c.Id = 0; return(c); }).ToList(); List <CATO> catoesE = new List <CATO>(), catoesOldE = new List <CATO>(); catoesE.AddRange(catoes); catoesOldE.AddRange(catoesOld); foreach (CATO cato in catoes) { CATO dublicateCato = catoesOldE.FirstOrDefault(c => c.Code == cato.Code && c.NameKK == cato.NameKK && c.NameRU == cato.NameRU); if (dublicateCato != null) { catoesOldE.Remove(dublicateCato); } } foreach (CATO cato in catoesOld) { CATO dublicateCato = catoesE.FirstOrDefault(c => c.Code == cato.Code && c.NameKK == cato.NameKK && c.NameRU == cato.NameRU); if (dublicateCato != null) { catoesE.Remove(dublicateCato); } } if (catoesE.Count() > 0 || catoesOldE.Count() > 0) { different = true; } } if (different) { foreach (CATO cato in _context.CATO.Where(c => c.ExpiredDateTime == null)) { cato.ExpiredDateTime = DateTime.Now; _context.Update(cato); } _context.CATO.AddRange(catoes); await _context.SaveChangesAsync(); importedCount = catoes.Count(); } } return(Ok(importedCount)); } catch (Exception exp) { return(Json(exp.Message)); } }
public ActionResult GetSownAreaChartImage(int? Year, int? CATOId) { if (CATOId == null) { return null; } List<decimal> values = new List<decimal>(); List<string> names = new List<string>(); var fields = db.fields .Where(f => f.catoid == CATOId) .Select(f => f.gid) .ToList(); var croprotations = db.CropRotations .Where(c => fields.Contains(c.fieldgid) && c.Year == Year) .ToList(); CATO cato = db.CATOes.Where(c => c.Id == CATOId).FirstOrDefault(); if(cato.CD == "00" && cato.EF == "00") { fields = db.fields .Select(f => f.gid) .ToList(); croprotations = db.CropRotations .Where(c => c.Year == Year) .ToList(); } foreach(CropRotation cr in croprotations) { if (!names.Contains(cr.CropRotationTypeId.ToString())) { names.Add(cr.CropRotationTypeId.ToString()); values.Add(0); } for (int i = 0; i < names.Count(); i++) { if(names[i] == cr.CropRotationTypeId.ToString()) { field field_ = db.fields.Where(f => f.gid == cr.fieldgid).FirstOrDefault(); values[i] += field_.area; break; } } } for(int j = 0; j < names.Count(); j++) { for (int i = 0; i < names.Count()-1; i++) { if(Convert.ToInt32(names[i]) > Convert.ToInt32(names[i+1])) { string sbufer = names[i]; names[i] = names[i + 1]; names[i + 1] = sbufer; decimal dbufer = values[i]; values[i] = values[i + 1]; values[i + 1] = dbufer; } } } for (int i = 0; i < names.Count(); i++) { int? name = Convert.ToInt32(names[i]); names[i] = db.CropRotationTypes.Where(c => c.Id == name).FirstOrDefault().Name; } for (int i = 0; i < values.Count(); i++) { values[i] = values[i] / 10000; } string title = cato.Name + " (" + Year.ToString() + ")"; var chart_SownArea = new Chart(width: 400, height: 300, theme: ChartTheme.Green) .AddTitle(title) .AddSeries( chartType: "Column", xValue: names, yValues: values, name: GeoServer.Resources.GrainProduction.SownAreaha) .AddLegend(); return File(chart_SownArea.ToWebImage().GetBytes(), "image/jpeg"); }
public ActionResult Upload(IEnumerable <HttpPostedFileBase> Files) { string report = ""; foreach (var file in Files) { report += "Файл\t" + file.FileName + ":<br/>"; int count = 0; if (file != null && file.ContentLength > 0) { BinaryReader b = new BinaryReader(file.InputStream); byte[] binData = b.ReadBytes((int)file.InputStream.Length); string result = Encoding.Default.GetString(binData); var strings = result.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string s in strings) { try { var c = s.Split("\t".ToCharArray()); CATO cato = new CATO() { AB = c[0], CD = c[1], EF = c[2], HIJ = c[3], Name = c[4] }; db.CATOes.Add(cato); count++; } catch { report += "строка\t\"" + s + "\" не распознана,<br/>"; } } } db.SaveChanges(); report += "загружено строк\t" + count.ToString() + ".<br/><br/>"; } ViewBag.Report = report; return(View()); //string report = ""; //foreach (var file in Files) //{ // report += "Файл\t" + file.FileName + ":<br/>"; // int count = 0; // if (file != null && file.ContentLength > 0) // { // BinaryReader b = new BinaryReader(file.InputStream); // byte[] binData = b.ReadBytes((int)file.InputStream.Length); // string result = Encoding.Default.GetString(binData); // var strings = result.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); // foreach (string s in strings) // { // try // { // var c = s.Split("\t".ToCharArray()); // int id = Convert.ToInt32(c[0]); // int cr = Convert.ToInt32(c[1]); // field field = db.fields.Where(f => f.gid == id).FirstOrDefault(); // field.croprotation = cr; // db.Entry(field).State = EntityState.Modified; // count++; // } // catch // { // report += "строка\t\"" + s + "\" не распознана,<br/>"; // } // } // } // db.SaveChanges(); // report += "загружено строк\t" + count.ToString() + ".<br/><br/>"; //} //ViewBag.Report = report; //return View(); }