/// <summary> /// 根据日程id删除日程 /// </summary> /// <param name="_id"></param> /// <returns></returns> public bool DelCalendarByID(int _id) { t.Entry <Calendar>(new Calendar { ID = _id }).State = System.Data.EntityState.Deleted; return(t.SaveChanges() > 0); }
/// <summary> /// 根据邮件id删除‘已发送’邮件 /// </summary> /// <param name="_id"></param> /// <returns></returns> public bool DelSendEmailByID(int _id) { t.Entry <SendEmailMessages>(new SendEmailMessages { ID = _id }).State = System.Data.EntityState.Deleted; return(t.SaveChanges() > 0); }
public int UpdateData(test data, testEntities entity) { int success = 0; //entity需一樣,所以移除 //testEntities entity = (testEntities)base.GetCurrentContext(); var entry = entity.Entry(data); if (entry.State == EntityState.Detached) { var set = entity.Set <test>(); test attachedEntity = set.Find(data.id); if (attachedEntity != null) { var attachedEntry = entity.Entry(attachedEntity); attachedEntry.CurrentValues.SetValues(data); } else { entry.State = EntityState.Modified; } } success = entity.SaveChanges(); return(success); }
/// <summary> /// 新增 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public static int AddEntity <T>(T entity) where T : class { db.Entry <T>(entity).State = EntityState.Added; return(db.SaveChanges()); // DbContextFactory db = new DbContextFactory(); // db. // db = new DbContextFactory.GetCurrentDbContext(); }
// [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "id,name,kana,tel,password")] user users) { if (ModelState.IsValid) { db.Entry(users).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(users)); }
public async Task <ActionResult> Edit([Bind(Include = "PostId,Message,ChartImageURL,NhanDinh,Vir")] Post post) { if (ModelState.IsValid) { post.PostedBy = 1; post.PostedDate = DateTime.Now; db.Entry(post).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(post)); }
public IHttpActionResult PutStudent(int id, Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != student.StudentId) { return(BadRequest()); } db.Entry(student).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// 根据岗位id删除岗位 /// </summary> /// <returns></returns> public bool DelPostByID(int _id) { t.Entry <PostInfo>(new PostInfo { ID = _id }).State = System.Data.EntityState.Deleted; return(t.SaveChanges() > 0); }
/// <summary> /// 根据部门id删除部门 /// </summary> /// <param name="_id"></param> /// <returns></returns> public bool DelDept(int _id) { t.Entry <Dept>(new Dept { ID = _id }).State = System.Data.EntityState.Deleted; return(t.SaveChanges() > 0); }
/// <summary> /// 根据id删除考勤记录 /// </summary> /// <returns></returns> public bool DelTimeSheetByID(int _id) { t.Entry <TimeSheet>(new TimeSheet { ID = _id }).State = System.Data.EntityState.Deleted; return(t.SaveChanges() > 0); }
public ActionResult Edit([Bind(Include = "Id,UserId,AlbumId,TrackId,ArtistId,Text,Rating,Type,Cdate")] Comment comment) { if (ModelState.IsValid) { db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } /* * Given the passed in attributes from comment, this will execute the follow SQL Code to update a comment: * USE [music] * GO * * UPDATE [dbo].[Comments] * SET [UserId] = UserId * ,[AlbumId] = AlbumId * ,[TrackId] = TrackId * ,[ArtistId] = ArtistId * ,[Text] = Text * ,[Rating] = Rating * ,[Type] = Type * ,[Cdate] = Cdate * WHERE Id = Id * GO */ return(View(comment)); }
/// <summary> /// 根据员工id删除该员工的工资发放记录(单条) /// </summary> /// <param name="_id"></param> /// <returns></returns> public bool DelByID(int _id) { testEntities t = new testEntities(); t.Entry <SalaryRecord>(new SalaryRecord { ID = _id }).State = System.Data.EntityState.Deleted; return(t.SaveChanges() > 0); }
public ActionResult Edit([Bind(Include = "Route_ID,Departure,Destination,Date,Airplane_ID")] Route route) { if (ModelState.IsValid) { db.Entry(route).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(route)); }
public ActionResult Edit([Bind(Include = "Id,Subject,Content,PosyDateTime")] Table table) { if (ModelState.IsValid) { db.Entry(table).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(table)); }
public ActionResult Edit([Bind(Include = "ID,Name,Designation,Salary")] EmployeeBIO employeeBIO) { if (ModelState.IsValid) { db.Entry(employeeBIO).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employeeBIO)); }
public ActionResult Edit([Bind(Include = "multiple_district_id,multiple_district_name_thai,multiple_district_name_eng")] MultipleDistrict multipleDistrict) { if (ModelState.IsValid) { db.Entry(multipleDistrict).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(multipleDistrict)); }
public ActionResult Edit([Bind(Include = "track_id,album_id,artist_id,license_title,track_bit_rate,track_comments,track_composer,track_date_created,track_date_recorded,track_disc_number,track_duration,track_explicit,track_explicit_notes,track_favorites,track_information,track_instrumental,track_interest,track_language_code,track_listens,track_lyricist,track_number,track_publisher,track_title,track_url")] Track track) { if (ModelState.IsValid) { db.Entry(track).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(track)); }
public ActionResult Edit([Bind(Include = "Customer_ID,FirstName,LastName,Email,Phone")] Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Edit([Bind(Include = "ID_MARCA,DESCRIPCION")] MARCA mARCA) { if (ModelState.IsValid) { db.Entry(mARCA).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mARCA)); }
public ActionResult Edit([Bind(Include = "ID_MODELO,ID_MARCA,DESCRIPCION_MODELO")] MODELO mODELO) { if (ModelState.IsValid) { db.Entry(mODELO).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID_MARCA = new SelectList(db.MARCA, "ID_MARCA", "DESCRIPCION", mODELO.ID_MARCA); return(View(mODELO)); }
public ActionResult Edit([Bind(Include = "district_id,district_name_thai,district_name_eng,multiple_district_id")] District district) { if (ModelState.IsValid) { db.Entry(district).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.multiple_district_id = new SelectList(db.MultipleDistricts, "multiple_district_id", "multiple_district_name_thai", district.multiple_district_id); return(View(district)); }
public ActionResult Edit([Bind(Include = "ProjectID,ProjectName,ProjectDescription,Projectstatus,StartDate,endData,price")] Project project) { if (ModelState.IsValid) { db.Entry(project).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(project)); }
public ActionResult deleteResult(int usrmovieId) { UserMovie toDeleteEntry = msContext.UserMovie.Where(x => x.UserMovieId == usrmovieId).FirstOrDefault(); msContext.Entry(toDeleteEntry).State = System.Data.Entity.EntityState.Deleted; msContext.SaveChanges(); string test = "hiii"; return(Json(test)); }
public void Update(T obj) { try { dbSet.Attach(obj); context.Entry(obj).State = EntityState.Modified; } catch (Exception ex) { throw; } }
public async Task <ActionResult> Edit([Bind(Include = "ID,UserId,StockFollowed,CreatedDate")] FollowStock followstock) { if (ModelState.IsValid) { db.Entry(followstock).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.UserLogins, "Id", "KeyLogin", followstock.UserId); return(View(followstock)); }
public void Update(int id) { using (testEntities db = new testEntities()) { var student = db.student.FirstOrDefault(r => r.id == id); student.name = "李四"; db.student.Attach(student); db.Entry(student).State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult Create(cow_device cow_device) { if (ModelState.IsValid) { //把十六进制转换成十进制 cow_device.deviceId = ConvertToTen(cow_device.showDeviceId); //如果转换出现异常则返回页面 if (cow_device.deviceId == null) { ViewBag.cowId = new SelectList(db.cow, "cowId", "cowId"); ViewBag.error = "请输入十六进制设备编号"; return(View(cow_device)); } var item = db.cow_device.AsNoTracking().SingleOrDefault(g => g.deviceId == cow_device.deviceId); if (item != null && item.id != cow_device.id) { ViewBag.cowId = new SelectList(db.cow, "cowId", "cowId"); ViewBag.error = "设备编号重复,请修改"; return(View(cow_device)); } if (cow_device.cowId != null) { cow_device device = db.cow_device.AsNoTracking().SingleOrDefault(g => g.cowId == cow_device.cowId); if (device != null) { device.cowId = null; db.Entry(device).State = EntityState.Modified; } } db.cow_device.Add(cow_device); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.cowId = new SelectList(db.cow, "cowId", "cowId"); return(View(cow_device)); }
public ActionResult Edit([Bind(Include = "ID_AUTO,ID_MODELO,PATENTE,ANO,COLOR,OBSERVACION")] AUTO aUTO) { String patenteAuto = aUTO.PATENTE; int year = DateTime.Now.Year; year += 2; // Validar que solo exista una patente por auto if (!db.AUTO.Any(o => o.ID_AUTO == aUTO.ID_AUTO && o.PATENTE == patenteAuto)) { if (db.AUTO.Any(o => o.PATENTE == patenteAuto)) { TempData["mensajeError"] = "La patente ingresada ya existe, intente con otra"; TempData["modelo"] = aUTO.ID_MODELO; TempData["patente"] = aUTO.PATENTE; TempData["año"] = aUTO.ANO; TempData["color"] = aUTO.COLOR; return(RedirectToAction("EDIT", aUTO.ID_AUTO)); } } else // Validar que el año ingresado no sea superior al actual + 2 if (aUTO.ANO > year) { TempData["mensajeError"] = "No puede ingresar autos con año superior a " + year; TempData["modelo"] = aUTO.ID_MODELO; TempData["patente"] = aUTO.PATENTE; TempData["año"] = aUTO.ANO; TempData["color"] = aUTO.COLOR; return(RedirectToAction("EDIT", aUTO.ID_AUTO)); } aUTO.OBSERVACION = "SIN OBSERVACIONES"; if (aUTO.ANO < 1990) { aUTO.OBSERVACION = "ANTIGUO"; } if (ModelState.IsValid) { db.Entry(aUTO).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID_MODELO = new SelectList(db.MODELO, "ID_MODELO", "DESCRIPCION_MODELO", aUTO.ID_MODELO); return(View(aUTO)); }
public void Update(T obj) { try { dbSet.Attach(obj); dbEntites.Entry(obj).State = EntityState.Modified; dbEntites.SaveChanges(); } catch (Exception ex) { throw; } }
/// <summary> /// 根据员工id删除该员工的工资发放记录(多条) /// </summary> /// <param name="_id"></param> /// <returns></returns> public bool DelByID(List <SalaryRecord> _srl) { testEntities t = new testEntities(); foreach (var item in _srl) { t.Entry <SalaryRecord>(new SalaryRecord { ID = item.ID }).State = System.Data.EntityState.Deleted; //t.SalaryRecord.Remove(item); } return(t.SaveChanges() > 0); }