public ActionResult Save(int?id, int?total, string name) { var leave = new leave(); if (id.HasValue) { leave = db.leaves.Single(x => x.id == id.Value); } leave.name = name; leave.defaultTotal = total; if (!id.HasValue) { db.leaves.InsertOnSubmit(leave); } try { repository.Save(); } catch (Exception ex) { return(SendJsonErrorResponse(ex)); } return(Json("Entry saved successfully".ToJsonOKMessage())); }
public async Task <IActionResult> PutLeave(int id, leave le) { if (id != le.id) { return(BadRequest()); } _appDbContext.Entry(le).State = EntityState.Modified; try { await _appDbContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!check(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <leave> > AddList(leave leave) { _appDbContext.Leave.Add(leave); await _appDbContext.SaveChangesAsync(); return(null); }
public async Task <ActionResult <leave> > GetLeave(int id) { leave le = await _appDbContext.Leave.FindAsync(id); if (le == null) { return(NotFound()); } return(le); }
public ActionResult Edit(int id, leave leave) { try { using (inventorymgtEntities inventorymgtEntities = new inventorymgtEntities()) { inventorymgtEntities.Entry(leave).State = System.Data.Entity.EntityState.Modified; inventorymgtEntities.SaveChanges(); } // TODO: Add update logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(leave leave) { try { using (inventorymgtEntities inventorymgtEntities = new inventorymgtEntities()) { inventorymgtEntities.leaves.Add(leave); inventorymgtEntities.SaveChanges(); } // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, FormCollection collection) { try { using (inventorymgtEntities inventorymgtEntities = new inventorymgtEntities()) { leave leave1 = inventorymgtEntities.leaves.Where(x => x.empId == id).FirstOrDefault(); inventorymgtEntities.leaves.Remove(leave1); inventorymgtEntities.SaveChanges(); } // TODO: Add delete logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public string Post(leave Leave) { Connection conn = new Connection(); MySqlConnection myConn = conn.GetConnection(); string query = string.Format("select count(student_ID) from leaving_record where student_ID='{0}'", Leave.student_ID); string health = string.Format("select count(*) from student where (student_ID='{0}' and (healthcode_color!='green' or currenthealth_status!=0))", Leave.student_ID); MySqlCommand h = new MySqlCommand(health, myConn); MySqlDataReader heal = h.ExecuteReader(); heal.Read(); int y = heal.GetInt16(0); heal.Close(); if (y != 0) { return("fail,you have risk"); } MySqlCommand queryNum = new MySqlCommand(query, myConn); MySqlDataReader reader1 = queryNum.ExecuteReader(); int num = 0; try { reader1.Read(); num = reader1.GetInt16(0) + 1; reader1.Close(); } catch (Exception ex) { Console.WriteLine(ex); } //string time=DateTime.Now.ToShortDateString(); string s = string.Format("insert into leaving_record values('{0}',{1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}')", Leave.student_ID, num.ToString(), Leave.destination, Leave.date, Leave.transport, Leave.trip_num, "9999-12-31", "未知", "0000"); MySqlCommand command = new MySqlCommand(s, myConn); int i = command.ExecuteNonQuery(); conn.Close(); if (i != 0) { return(num.ToString()); } return("fail"); }