public async Task <IActionResult> Edit(int id, [Bind("AutoId,StdCatId,StdCategory,LoginName")] StdCat stdCat) { if (id != stdCat.StdCatId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(stdCat); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StdCatExists(stdCat.StdCatId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(stdCat)); }
public async Task <IActionResult> PostStdCat([FromBody] StdCat stdCat) { int HasCat = 0; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var conn = _context.Database.GetDbConnection(); if (conn.State == ConnectionState.Closed) { await conn.OpenAsync(); } using (var command = conn.CreateCommand()) { MySql = "SELECT StdCatID FROM StdCat"; MySql = MySql + " WHERE Dormant = 0"; MySql = MySql + " AND StdCategory = '" + stdCat.StdCategory + "'"; command.CommandType = CommandType.Text; command.CommandText = MySql; DbDataReader kMyReader = command.ExecuteReader(); if (kMyReader.HasRows) { HasCat = 1; return(BadRequest()); } kMyReader.Close(); if (HasCat == 0) { MySql = " INSERT INTO StdCat ( StdCatID, StdCategory, "; MySql = MySql + " Dormant, LoginName, ModTime, cTerminal, dBID) Values (0, '"; MySql = MySql + stdCat.StdCategory + "'"; MySql = MySql + ", 0,'" + strLoginName + "'," + GenFunc.GloFunc.ToOADate(DateTime.Now); MySql = MySql + ",'" + Terminal + "'," + stdCat.DBid + ")"; command.CommandType = CommandType.Text; command.CommandText = MySql; command.ExecuteNonQuery(); } } //UpdateAcaSession(acaSession); // await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(CreatedAtAction("GetStdCat", new { id = stdCat.AutoId }, stdCat)); }
public async Task <IActionResult> PutStdCat([FromRoute] int id, [FromBody] StdCat stdCat) { var ssid = stdCat.StdCatId; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var conn = _context.Database.GetDbConnection(); if (conn.State == ConnectionState.Closed) { await conn.OpenAsync(); } using (var command = conn.CreateCommand()) { MySql = " UPDATE StdCat SET "; MySql = MySql + " StdCategory = '" + stdCat.StdCategory + "'"; MySql = MySql + " WHERE StdCatID = " + stdCat.StdCatId; MySql = MySql + " AND Dormant = 0"; MySql = MySql + " AND dBID = " + stdCat.DBid; command.CommandType = CommandType.Text; command.CommandText = MySql; command.ExecuteNonQuery(); } //UpdateAcaSession(acaSession); // await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StdCatExists(ssid)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("StdCatId,StdCategory,LoginName")] StdCat stdCat) { if (ModelState.IsValid) { if (!StdCatExists(stdCat.StdCategory)) { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(GloVar.iBaseURI); MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); client.DefaultRequestHeaders.Accept.Add(contentType); string stringData = JsonConvert.SerializeObject(stdCat); var contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("/api/StdCats", contentData).Result; ViewBag.Message = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { ViewBag.Remark = "Creation of Students Category '" + stdCat.StdCategory + "' Successful"; return(View()); } else { ViewBag.Remark = "Creation of Students Category '" + stdCat.StdCategory + "' Failed!. Please Try Again"; return(View(stdCat)); } } } else { ViewBag.Remark = "Failed Students Category '" + stdCat.StdCategory + "' Already Exists."; return(View(stdCat)); } } else { ViewBag.Remark = "Failed! Students Category '" + stdCat.StdCategory + "' Unable To create. PleaseTry Again."; return(View(stdCat)); } }
public IEnumerable <StdCat> GetStdCat(int mdBId) { List <StdCat> stdCatList = new List <StdCat>(); var conn = _context.Database.GetDbConnection(); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (var command = conn.CreateCommand()) { MySql = " SELECT StdCatID, StdCategory FROM stdCat WITH (NOLOCK)"; MySql = MySql + " WHERE Dormant = 0"; MySql = MySql + " AND dBID = " + mdBId; command.CommandType = CommandType.Text; command.CommandText = MySql; DbDataReader kMyReader = command.ExecuteReader(); if (kMyReader.HasRows) { while (kMyReader.Read()) { StdCat stdCat = new StdCat(); if (!kMyReader.IsDBNull(0)) { stdCat.StdCatId = kMyReader.GetInt32(0); } if (!kMyReader.IsDBNull(1)) { stdCat.StdCategory = kMyReader.GetString(1); } stdCatList.Add(stdCat); } } } return(stdCatList); }