public List <Ma> SinhMa(List <Ma> dsma, int sl, int sokitu, DateTime ngayhethan) { for (int i = 0; i < sl; i++) { string s = ""; for (int j = 0; j < sokitu; j++) { char kitu = (char)r.Next(65, 91); s += kitu; } if (isTrungma(dsma, s)) { i--; } //mã sinh ra hop lệ k bi trùng else { Ma ma = new Ma(); ma.NoiDung = s; ma.ThoiGianHetHan = ngayhethan; ma.SoKiTu = sokitu; dsma.Add(ma); } } return(dsma); }
public int Sua(object a) { DbContextTransaction transaction = db.Database.BeginTransaction(); try { if (a.GetType().ToString().IndexOf("NguoiDung") > 1) { NguoiDung temp = (NguoiDung)a; temp = db.NguoiDungs.Where(s => s.IdND == temp.IdND).FirstOrDefault(); db.Entry(temp).CurrentValues.SetValues(a); } else { Ma temp = (Ma)a; temp = db.Mas.Where(s => s.IdMa == temp.IdMa).First(); db.Entry(temp).CurrentValues.SetValues(a); } db.SaveChanges(); transaction.Commit(); return(1); } catch { transaction.Rollback(); return(0); } }
public bool isMaCoTheKhoa(Ma ma) { if (ma.TrangThai != 2 && ma.TrangThai != 1 && ma.TrangThai != 3) { return(true); } else { return(false); } }