public async Task <IActionResult> PostStdHouse([FromBody] StdHouse stdHouse) { 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 = " INSERT INTO StdHouse ( StdHouseID, StdHouse, "; MySql = MySql + " Dormant, LoginName, ModTime, cTerminal, dBID) Values (0, '"; MySql = MySql + stdHouse.StHouse + "'"; MySql = MySql + ", 0,'" + strLoginName + "'," + GenFunc.GloFunc.ToOADate(DateTime.Now); MySql = MySql + ",'" + Terminal + "'," + stdHouse.DBid + ")"; command.CommandType = CommandType.Text; command.CommandText = MySql; command.ExecuteNonQuery(); } //UpdateAcaSession(acaSession); // await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(CreatedAtAction("GetStdHouse", new { id = stdHouse.StdHouseId }, stdHouse)); }
public async Task <IActionResult> Edit(int id, [Bind("StdHouseId,StHouse")] StdHouse stdHouse) { if (id != stdHouse.StdHouseId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(stdHouse); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StdHouseExists(stdHouse.StdHouseId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(stdHouse)); }
public async Task <IActionResult> PutStdHouse([FromRoute] int id, [FromBody] StdHouse stdHouse) { var ssid = stdHouse.StdHouseId; 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 StdHouse SET "; MySql = MySql + " StdHouse = '" + stdHouse.StHouse + "'"; MySql = MySql + " WHERE StdHouseID = " + stdHouse.StdHouseId; MySql = MySql + " AND Dormant = 0"; MySql = MySql + " AND dBID = " + stdHouse.DBid; command.CommandType = CommandType.Text; command.CommandText = MySql; command.ExecuteNonQuery(); } //UpdateAcaSession(acaSession); // await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StdHouseExists(ssid)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult Create([Bind("StHouse")] StdHouse stdHouse) { if (ModelState.IsValid) { if (!StdHouseExists(stdHouse.StHouse)) { 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(stdHouse); var contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("/api/StdHouses", contentData).Result; ViewBag.Message = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { ViewBag.Remark = "Creation of Color/House '" + stdHouse.StHouse + "' Successful"; return(View()); } else { ViewBag.Remark = "Creation of Color/House '" + stdHouse.StHouse + "' Failed!. Please Try Again"; return(View(stdHouse)); } } } else { ViewBag.Remark = "Failed Color/House '" + stdHouse.StHouse + "' Already Exists."; return(View(stdHouse)); } } else { ViewBag.Remark = "Failed! Color/House '" + stdHouse.StHouse + "' Unable To create. PleaseTry Again."; return(View(stdHouse)); } }
public IEnumerable <StdHouse> GetStdHouse(int mdBId) { List <StdHouse> stdHouseList = new List <StdHouse>(); var conn = _context.Database.GetDbConnection(); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (var command = conn.CreateCommand()) { MySql = " SELECT StdHouseID, StdHouse FROM StdHouse 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()) { StdHouse stdHouse = new StdHouse(); if (!kMyReader.IsDBNull(0)) { stdHouse.StdHouseId = kMyReader.GetInt32(0); } if (!kMyReader.IsDBNull(1)) { stdHouse.StHouse = kMyReader.GetString(1); } stdHouseList.Add(stdHouse); } } } return(stdHouseList); }