public ActionResult Create([Bind(Include = "MemberID,MemberName,MemberEmail,MemberPassword,ConfirmPassword,MemberPhone,MemberType,TutorImage,TutorPortfolio,TutorGit")] Member member) { var lst = new List <Member>(); var query = from x in db.Members where x.MemberEmail.Equals(member.MemberEmail) select x; lst.AddRange(query); if (lst.Count != 0) { MessageBox.Show("이미 존재하는 이메일 입니다."); return(View()); } if (ModelState.IsValid) { db.Members.Add(member); db.SaveChanges(); return(RedirectToAction("SignIn", "Member")); } return(View("Create")); }
public ActionResult Create(StudentViewModel model) { try { if (ModelState.IsValid) { var student = new Student { FirstName = model.FirstName, LastName = model.LastName, EMail = model.EMail, Phone = model.Phone, ParentName = model.ParentName, Address = model.Address, Grade = model.Grade }; AddOrUpdateCourses(student, model.Courses); db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(View(model)); }
public IHttpActionResult PutClass(int id, Class @class) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != @class.Id) { return(BadRequest()); } db.Entry(@class).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ClassExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "AID,Name,DOB")] Athlete athlete) { if (ModelState.IsValid) { db.Athletes.Add(athlete); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(athlete)); }
public ActionResult DeleteClass(int id, string newName, string newDepart) { Class C = cc.ClassList.Where(c => c.class_id == id).FirstOrDefault(); C.class_name = newName; C.class_depart = newDepart; cc.ClassList.Attach(C); cc.Entry(C).State = System.Data.EntityState.Modified; cc.SaveChanges(); return(RedirectToAction("ManageClassPage", "Head")); }
public ActionResult Create([Bind(Include = "StudentID,firstName,lastName,email")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create([Bind(Include = "ApplicationID,ApplicationLevel,LectureID,MemberID")] Application application) { if (ModelState.IsValid) { db.Applications.Add(application); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LectureID = new SelectList(db.Lectures, "LectureID", "LectureTitle", application.LectureID); return(View(application)); }
public ActionResult Create([Bind(Include = "ReviewID,ReviewContent,ReviewGrade,LectureID,MemberID")] Review review) { if (ModelState.IsValid) { db.Reviews.Add(review); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LectureID = new SelectList(db.Lectures, "LectureID", "LectureTitle", review.LectureID); return(View(review)); }
public ActionResult Create([Bind(Include = "ApplyScheduleID,ApplyDayofweek,ApplyScheduleTime,ApplicationID")] ApplySchedule applySchedule) { if (ModelState.IsValid) { db.ApplySchedules.Add(applySchedule); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ApplicationID = new SelectList(db.Applications, "ApplicationID", "ApplicationLevel", applySchedule.ApplicationID); return(View(applySchedule)); }
public ActionResult Create([Bind(Include = "CurrentClassOfferingID,CID,Quarter,Year,timeOffered")] CurrentClassOffering currentClassOffering) { if (ModelState.IsValid) { db.CurrentClassOfferings.Add(currentClassOffering); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CID = new SelectList(db.ClassOfferings, "ClassOfferingID", "CourseCode", currentClassOffering.CID); return(View(currentClassOffering)); }
public ActionResult Create([Bind(Include = "LicenseID,LicenseName,LicenseAgency,LicenseAcqDate,LicenseNumber,MemberID")] License license) { if (ModelState.IsValid) { db.Licenses.Add(license); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MemberID = new SelectList(db.Members, "MemberID", "MemberName", license.MemberID); return(View(license)); }
public ActionResult Create([Bind(Include = "ClassesTakenID,StudentID,CID,GPA")] ClassesTaken classesTaken) { if (ModelState.IsValid) { db.ClassesTakens.Add(classesTaken); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CID = new SelectList(db.CurrentClassOfferings, "CurrentClassOfferingID", "timeOffered", classesTaken.CID); ViewBag.StudentID = new SelectList(db.Students, "StudentID", "firstName", classesTaken.StudentID); return(View(classesTaken)); }
private void SeedCustomers(ClassContext context) { if (context.Customers.Select(c => c).Count() == 0) { context.Customers.Add(new Customer { ID = 1, Name = "Customer 1", Address = "Address for Customer 1" }); context.Customers.Add(new Models.Customer { ID = 2, Name = "Customer 2", Address = "Address for Customer 2" }); context.Customers.Add(new Models.Customer { ID = 3, Name = "Customer 3", Address = "Address for Customer 3" }); context.SaveChanges(); } }
private void SeedAccountTypes(ClassContext context) { if (context.AccountTypes.Select(at => at).Count() == 0) { context.AccountTypes.AddOrUpdate(at => at.ID, new Models.AccountType { ID = 1, TypeName = "Current", Conditions = "Current Account Terms and conditions apply." }, new Models.AccountType { ID = 2, TypeName = "Savings", Conditions = "Savings Account Terms and conditions apply." }, new Models.AccountType { ID = 3, TypeName = "Deposit", Conditions = "Deposit Account Terms and conditions apply." } ); context.SaveChanges(); } }
public DocenteController(ClassContext context) { _context = context; if (_context.Docentes.Count() == 0) { DocenteItem docente = new DocenteItem(); docente.identificacion = 1003242276; docente.tipo_Documento = "CEDULA"; docente.primer_Nombre = "JORGE"; docente.segundo_Nombre = "DANIEL"; docente.primer_Apellido = "RINCONES"; docente.segundo_Apellido = "FERNANDEZ"; docente.fecha_Nacimiento = Convert.ToDateTime("3/11/2000").Date; docente.genero = "MASCULINO"; docente.email = "*****@*****.**"; docente.telefono = 3004128610; docente.cargo = "DOCENTE"; docente.estadoSys = "ACTIVO"; docente.tipo_Docente = "CATEDRATICO"; docente.user_Name = "" + docente.identificacion; docente.contrasena = "" + docente.identificacion; // Crea un nuevo item si la coleccion esta vacia, // lo que significa que no puedes borrar todos los Items. //_context.Docentes.Add(new DocenteItem { Tipo_Docente = "CATEDRATICO" }); _context.Docentes.Add(docente); _context.SaveChanges(); } }
public DocenteController(ClassContext context) { _context = context; if (_context.DocenteItems.Count() == 0) { // Crea un nuevo item si la coleccion esta vacia, // lo que significa que no puedes borrar todos los Items. //_context.Docentes.Add(new DocenteItem { Tipo_Docente = "CATEDRATICO" }); _context.DocenteItems.Add(new DocenteItem { Id = 1, Tipo_Documento = "CEDULA", Identificacion = "1003242276", Primer_Nombre = "JORGE", Segundo_Nombre = "DANIEL", Primer_Apellido = "RINCONES", Segundo_Apellido = "FERNANDEZ", Fecha_Nacimiento = "3/11/2000", Edad = 19, Genero = "MASCULINO", Email = "*****@*****.**", Telefono = "3004128610", //Contraseña = "12345", Cargo = "DOCENTE", Fecha_Vinculacion = "3/11/2019", EstadoSys = "ACTIVO", Tipo_Docente = "CATEDRATICO" }); _context.SaveChanges(); } }
public DocenteController(ClassContext context) { _context = context; if (_context.Docentes.Count() == 0) { // Crea un nuevo item si la coleccion esta vacia, // lo que significa que no puedes borrar todos los Items. //_context.Docentes.Add(new DocenteItem { Tipo_Docente = "CATEDRATICO" }); _context.Docentes.Add(new DocenteItem { tipo_Documento = "CEDULA", identificacion = "1003242276", primer_Nombre = "JORGE", segundo_Nombre = "DANIEL", primer_Apellido = "RINCONES", segundo_Apellido = "FERNANDEZ", fecha_Nacimiento = Convert.ToDateTime("3/11/2000").Date, genero = "MASCULINO", email = "*****@*****.**", telefono = 3004128610, cargo = "DOCENTE", estadoSys = "ACTIVO", tipo_Docente = "CATEDRATICO", user_Name = "Docente", contrasena = "12345" }); _context.SaveChanges(); } }
public TipoActividadController(ClassContext context) { _context = context; if (_context.TipoActividades.Count() == 0) { _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "COMITÉ DE EVALUACIÓN" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "TUTORÍAS" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "INVESTIGACIÓN" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "EXTENCIÓN" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "MATERIAL DE APOYO" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "TRABAJO DE GRADO" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "COOPERACIÓN INTERISTITUCIONAL" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "CRECIMIENTO PROFECIONAL" }); _context.TipoActividades.Add(new TipoActividad { nombre_Actividad = "ENCARGO ADMINISTRATIVO" }); _context.SaveChanges(); } }
//-------------------------upDate--------------------------------- //será em feito em sites e web API (aplicações desconectadas) private static void updateAppDisconected() { Course course; //aqui é feito a conexão quando entra no app para o usuairo conseguir mexer //e selecionado o que irá ser mandado para o usuario using (var context = new ClassContext()) { context.Database.Log = Console.WriteLine; course = context.Course.FirstOrDefault(); } //depois fecha a conexao e o usuario na pagina pode editar algo // durante sua conexao course.AuthorId = 1; //depois é preciso salvar todas as alterações que foram feitas using (var context = new ClassContext()) { context.Database.Log = Console.WriteLine; //context.Course.Attach(course); - campo não obrigatório, porém serve para avisar para ter atenção nesse objeto //para fazer o update é preciso pegar o objeto e dizer qual o estado dele para poder salvar context.Entry(course).State = EntityState.Modified; context.SaveChanges();//salva as alterações } }
//------------------------Adicionar -------------------------------- private static void addDataRelationally() { //nesse caso desejei criar o Author e logo junto os cursos var author = new Author { Name = "Raphael", Age = 27 }; var course1 = new Course { Name = "Direito" }; var course2 = new Course { Name = "Direito Civil" }; using (var context = new ClassContext()) { context.Database.Log = Console.WriteLine; //primeiramente adicion o author context.Author.Add(author); //como já instanciei de lista de course nos autores no construtor //é preciso só adicionar os cursos na lista que eu estou desejando //o entityFrameWork já ira entender que esses novos cursos criados //no banco irá se relacionar com o autor author.Course.Add(course1); author.Course.Add(course2); context.SaveChanges(); } }
public void Delete(Classandgrade classandgrade) { using (var db = new ClassContext()) { db.Entry(classandgrade).State = EntityState.Deleted; db.SaveChanges(); } }
public void Add(Classandgrade classandgrade) { using (var db = new ClassContext()) { db.Classandgrade.Add(classandgrade); db.SaveChanges(); } }
public void Add(Class Class) { using (var db = new ClassContext()) { db.ClassA.Add(Class); db.SaveChanges(); } }
//根据ID删除 public void Delete(Clas clas) { using (var db = new ClassContext()) { //修改博客实体状态 db.Entry(clas).State = EntityState.Deleted; db.SaveChanges(); } }
public void IncluirNoticia(NoticiasModel not) { using (var ctx = new ClassContext()) { ctx.Noticia.Add(not); ctx.SaveChanges(); } //noticia.Add(not); }
public void CadastrarContato(ContatoModel not) { using (var ctx = new ClassContext()) { ctx.Contato.Add(not); ctx.SaveChanges(); } //noticia.Add(not); }
public void Delete(ClassName blog) { using (var db = new ClassContext()) { db.Entry(blog).State = EntityState.Deleted; db.SaveChanges(); } }
public void Update(ClassName blog) { using (var db = new ClassContext()) { //修改博客实体状态 db.Entry(blog).State = EntityState.Modified; //保存状态 db.SaveChanges(); } }
public void SaveArtToDB() { using (ClassContext ccx = new ClassContext()) { ccx.classArt.AddOrUpdate(classArt); ccx.SaveChanges(); } classArt = new ClassArt(); listClassArt.Clear(); }
public void Update(Clas clas) { //设置上下文生存期 using (var db = new ClassContext()) { //用枚举来表示修改状态 db.Entry(clas).State = EntityState.Modified; //保存状态改变 db.SaveChanges(); } }