// Create public int Create(SEED seedModel) { seedModel.Is_Deleted = false; db.SEEDs.Add(seedModel); db.SaveChanges(); return(seedModel.Id_Seed); }
public IHttpActionResult PostSEED(SEED sEED) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.SEED.Add(sEED); try { db.SaveChanges(); } catch (DbUpdateException) { if (SEEDExists(sEED.id_seed)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = sEED.id_seed }, sEED)); }
public IHttpActionResult PutSEED(int id, SEED sEED) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != sEED.id_seed) { return(BadRequest()); } db.Entry(sEED).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SEEDExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetSEED(int id) { SEED sEED = db.SEED.Find(id); if (sEED == null) { return(NotFound()); } return(Ok(sEED)); }
public bool Create(SEED seed) { try { seed.Is_Deleted = false; db.SEEDs.Add(seed); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public IHttpActionResult DeleteSEED(int id) { SEED sEED = db.SEED.Find(id); if (sEED == null) { return(NotFound()); } db.SEED.Remove(sEED); db.SaveChanges(); return(Ok(sEED)); }
public ActionResult Edit(SEED model) { var result = dao.Edit(model); if (result) { return(RedirectToAction("SeedIndex")); } else { ModelState.AddModelError("", "Cập nhật thất bại !!!"); SetViewBagProduct(); return(View(model)); } }
public bool Edit(SEED seed) { try { var targetEdit = db.SEEDs.Find(seed.Id_Seed); targetEdit.Id_Product = seed.Id_Product; targetEdit.Name_Seed = seed.Name_Seed; targetEdit.Code_Seed = seed.Code_Seed; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult Create(SEED seedModel) { if (ModelState.IsValid) { var result = dao.Create(seedModel); if (result > 0) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Tạo mới thất bại !!!"); } } return(View()); }
// Update public bool Update(SEED seedModel) { var targetUpdate = db.SEEDs.Find(seedModel.Id_Seed); try { targetUpdate.Name_Seed = seedModel.Name_Seed; targetUpdate.Code_Seed = seedModel.Code_Seed; db.SaveChanges(); return(true); } catch (Exception e) { return(false); throw new Exception(e.Message); } }
protected override SEED CreateSeed(byte[] password) { byte[] pdbBytes; using (var pdb = new Rfc2898DeriveBytes(password, this.Salt, this.Iter)) pdbBytes = pdb.GetBytes(20); var seed = new SEED { ModType = SEED.MODE.AI_CBC, KeyBytes = new byte[16], IV = new byte[16] }; Buffer.BlockCopy(pdbBytes, 0, seed.KeyBytes, 0, 16); Buffer.BlockCopy(this.m_iv, 0, seed.IV, 0, 16); return(seed); }
public ActionResult Edit(SEED seedModel) { if (ModelState.IsValid) { var result = dao.Update(seedModel); if (result) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Cập nhật thất bại"); } } var seedModelState = dao.Details(seedModel.Id_Seed); return(View(seedModelState)); }
protected override SEED CreateSeed(byte[] password) { byte[] pdbBytes; using (var pdb = new PasswordDeriveBytes(password, this.Salt, "SHA1", this.Iter)) pdbBytes = pdb.GetBytes(20); var seed = new SEED { ModType = SEED.MODE.AI_CBC, KeyBytes = new byte[16], IV = new byte[16] }; Buffer.BlockCopy(pdbBytes, 0, seed.KeyBytes, 0, 16); using (var sha1 = new SHA1CryptoServiceProvider()) Buffer.BlockCopy(sha1.ComputeHash(pdbBytes, 16, 4), 0, seed.IV, 0, 16); return(seed); }
////Level static void Level(NODE[] n) { int maxLG = 0; Boolean conti = false; do { //creat seed for (int i = 0; i < n.Length; i++) { if (n[i].LGroup > maxLG) { maxLG = n[i].LGroup; } } if ((maxLG + 1) == 1) { break; } SEED[] tempS = new SEED[maxLG + 1]; for (int i = 0; i < tempS.Length; i++) { double sumX = 0, sumY = 0; int nodeCounter = 0; for (int j = 0; j < n.Length; j++) { if (n[j].LGroup == i) { nodeCounter++; sumX += n[j].x; sumY += n[j].y; } } tempS[i].x = sumX / nodeCounter; tempS[i].y = sumY / nodeCounter; //write dis for (int j = 0; j < n.Length; j++) { if (n[j].LGroup == i) { n[j].Distance = Distance(n[j].x, n[j].y, tempS[i].x, tempS[i].y); } } } //math distance int minS1 = 0, minS2 = 0; double minDis = double.MaxValue; for (int i = 0; i < tempS.Length - 1; i++) { for (int j = i + 1; j < tempS.Length; j++) { double tempDis = Distance(tempS[i].x, tempS[i].y, tempS[j].x, tempS[j].y); if (tempDis < minDis) { minDis = tempDis; minS1 = i; minS2 = j; } } } if (minDis < limit) { conti = true; for (int i = 0; i < n.Length; i++) { if (n[i].LGroup == minS2) { n[i].LGroup = minS1; } else if (n[i].LGroup > minS2) { n[i].LGroup--; } } } else { break; } }while (conti == true); }
////KMean static void KMeans(NODE[] n) { //craet seed SEED[] s = new SEED[(int)(n.Length / 10)]; for (int i = 0; i < s.Length; i++) { Random rand = new Random(Guid.NewGuid().GetHashCode()); int randIdex = rand.Next(0, n.Length - 1); s[i].x = n[randIdex].x; s[i].y = n[randIdex].y; } //check seed Boolean conti = false;//繼續否? int falseSeed = 0; do { conti = false; for (int i = 0; i < s.Length - 1; i++) { if (s[i].x == -1) { continue; } for (int j = i + 1; j < s.Length; j++) { if (s[j].x == -1) { continue; } double dis = Distance(s[i].x, s[i].y, s[j].x, s[j].y); if (dis < limit) { falseSeed++; conti = true; s[i].x = (s[i].x + s[j].x) / 2; s[i].y = (s[i].y + s[j].y) / 2; s[j].x = -1; } } } }while (conti == true); if (falseSeed > 0) { SEED[] tempS = new SEED[s.Length - falseSeed]; int counter = 0; for (int i = 0; i < s.Length; i++) { if (s[i].x == -1) { continue; } else { tempS[counter].x = s[i].x; tempS[counter].y = s[i].y; counter++; } } s = new SEED[tempS.Length]; for (int i = 0; i < s.Length; i++) { s[i].x = tempS[i].x; s[i].y = tempS[i].y; } } //show seed System.Console.WriteLine("\nKM 種子:"); for (int i = 0; i < s.Length; i++) { System.Console.WriteLine("Seed[{0}]=[{1},{2}]", i, s[i].x, s[i].y); } //math KM do { conti = false; SEED[] tempS = new SEED[s.Length]; for (int i = 0; i < tempS.Length; i++) { tempS[i].x = s[i].x; tempS[i].y = s[i].y; } //math for (int i = 0; i < n.Length; i++) { double minDis = double.MaxValue; int minS = 0; for (int j = 0; j < s.Length; j++) { double dis = Distance(n[i].x, n[i].y, s[j].x, s[j].y); if (dis < minDis) { minDis = dis; minS = j; } } n[i].KGroup = minS; n[i].Distance = minDis; } //remath seed for (int i = 0; i < s.Length; i++) { double sumX = 0, sumY = 0; int nodeCounter = 0; for (int j = 0; j < n.Length; j++) { if (n[j].KGroup == i) { sumX += n[j].x; sumY += n[j].y; nodeCounter++; } } if (nodeCounter == 0) { continue; } else { s[i].x = sumX / nodeCounter; s[i].y = sumY / nodeCounter; } } //check seed for (int i = 0; i < s.Length; i++) { if (s[i].x != tempS[i].x || s[i].y != tempS[i].y) { conti = true; } } }while (conti == true); System.Console.WriteLine("KMeans 分類結束\n"); }