public void DeleteCourse(int id) { var course = GetCourseById(id); _db.Entry(course).State = System.Data.Entity.EntityState.Deleted; _db.SaveChanges(); }
public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName,Email,PhoneNumber,UserName,UserPassword,UserType,Language")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public User GetUserById(int id) { var user = _db.Users.SingleOrDefault(x => x.Id == id); _db.Entry(user).Reload(); return(user); }
public ActionResult Edit([Bind(Include = "ID,Nombre,ApellidoPaterno,ApellidoMaterno,Telefono,Correo,RFC,FechaAsoc")] Cliente cliente) { if (ModelState.IsValid) { db.Entry(cliente).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cliente)); }
public ActionResult Edit([Bind(Include = "DocumentID,TaskID")] Document document) { if (ModelState.IsValid) { db.Entry(document).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(document)); }
public ActionResult Edit([Bind(Include = "UserId,Name,Username,Password,Permission")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "CommentID,TaskID,UserID,CommentText,CommentDate")] Comment comment) { if (ModelState.IsValid) { db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TaskID = new SelectList(db.Tasks, "TaskID", "TaskName", comment.TaskID); ViewBag.UserID = new SelectList(db.Users, "UserID", "FirstName", comment.UserID); return(View(comment)); }
public ActionResult Edit([Bind(Include = "ProjectID,UserID,ProjectKey,ProjectName,ProjectDescription,ProjectStartDate,ProjectEndDate,ProjectStatus")] Project project) { if (ModelState.IsValidField("ProjectStartDate") && ModelState.IsValidField("ProjectEndDate") && project.ProjectStartDate > project.ProjectEndDate) { ModelState.AddModelError("ProjectEndDate", @Resources.Resource.Enddateshouldbegraterthanstartdate); } if (ModelState.IsValid) { project.ProjectKey = project.ProjectKey.ToUpper(); db.Entry(project).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.Users.Where(p => p.UserType == UserType.ProjectManager), "UserID", "FullName", project.UserID); return(View(project)); }
public ActionResult Edit([Bind(Include = "ID,Nombre,Descripcion,Costo,Estado,FechaCreacion")] Proyecto proyecto) { if (ModelState.IsValid) { db.Entry(proyecto).State = EntityState.Modified; db.SaveChanges(); var x = RedirectToAction("Index"); Cliente cliente = (Cliente)Session["cliente"]; if (cliente != null) { x = RedirectToAction("Index", new { id = cliente.ID }); } return(x); } return(View(proyecto)); }
public ActionResult Edit([Bind(Include = "ID,Descripcion,FechaCreacion,Estado")] Error error) { if (ModelState.IsValid) { db.Entry(error).State = EntityState.Modified; db.SaveChanges(); var x = RedirectToAction("Index"); Proyecto proyecto = (Proyecto)Session["proyecto"]; if (proyecto != null) { x = RedirectToAction("Index", new { id = proyecto.ID }); } return(x); } return(View(error)); }
public static void UpdateChatGroup(int GroupID, ChatGroupInfo GroupInfo) { var _Context = new SystemContext(); var entity = _Context.ChatGroupEntity.Find(GroupID); entity.GroupName = GroupInfo.GroupName; entity.GroupDesc = GroupInfo.GroupDesc; _Context.Entry(entity).State = System.Data.Entity.EntityState.Modified; // 先清空小组成员 var items = _Context.ChatGroupEmpsEntity.Where(g => g.GroupID == GroupID); foreach (var item in items) { _Context.ChatGroupEmpsEntity.Remove(item); } // 重新生成小组成员 _Context.ChatGroupEmpsEntity.Add(new ChatGroupEmpsEntity() { GroupID = entity.GroupID, EmpID = entity.CreateEmpID }); foreach (var id in GroupInfo.Emps) { if (id != GroupInfo.CreateEmpID) { _Context.ChatGroupEmpsEntity.Add(new ChatGroupEmpsEntity() { GroupID = entity.GroupID, EmpID = id }); } } _Context.SaveChanges(); var notifySrv = UnityContainerHelper.GetServer <WSHandler>(); notifySrv.Send(new { TargetGroup = entity.GroupID, MessageType = 104 }); }
public static void RemoveChatGroup(int GroupID) { var _Context = new SystemContext(); var entity = _Context.ChatGroupEntity.Find(GroupID); entity.IsDelete = true; _Context.Entry(entity).State = System.Data.Entity.EntityState.Modified; _Context.SaveChanges(); var notifySrv = UnityContainerHelper.GetServer <WSHandler>(); notifySrv.Send(new { TargetGroup = entity.GroupID, MessageType = 105 }); }
public async Task <IActionResult> PutCode([FromBody] Code code) { _context.Entry(code).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (_context.Codes.Count(c => c.Key == code.Key && c.Value == code.Value) == 0) { return(NotFound()); } else { throw; } } return(Ok()); }
public ActionResult Edit([Bind(Include = "TaskID,ProjectID,TaskName,TaskDescription,TaskStartDate,TaskEndDate,TaskStatus,UserID")] Task task) { if (ModelState.IsValidField("TaskStartDate") && ModelState.IsValidField("TaskEndDate") && task.TaskStartDate > task.TaskEndDate) { ModelState.AddModelError("TaskEndDate", @Resources.Resource.Enddateshouldbegraterthanstartdate); } if (ModelState.IsValid) { db.Entry(task).State = EntityState.Modified; db.SaveChanges(); string fromDetails = Request.QueryString["from"]; if (fromDetails != null) { return(RedirectToAction("Details", new { id = task.TaskID })); } return(RedirectToAction("Index")); } ViewBag.ProjectID = new SelectList(db.Projects, "ProjectID", "ProjectName", task.ProjectID); ViewBag.UserID = new SelectList(db.Users, "UserID", "FirstName", task.UserID); return(View(task)); }
public async Task <IActionResult> PutParameter([FromBody] Parameter parameter) { _context.Entry(parameter).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (_context.Parameters.Count(p => p.Key == parameter.Key) == 0) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> EditB(EditBookViewModel model, IFormFile file) { if (ModelState.IsValid) { Book book = _systemContext.Books.Include(b => b.Chapters).FirstOrDefault(b => b.Id == model.Id); if (book != null) { book.Name = model.BookName; book.Author = model.Author; book.Articl = model.Articl; book.Description = model.Description; book.Year = model.Year; book.Count = model.Count; string path = book.BookPicture; if (!string.IsNullOrEmpty(book.BookPicture) && file != null) { System.IO.File.Delete(_appEnvironment.WebRootPath + book.BookPicture); path = ""; } if (file != null) { path = @"/files/book/" + book.Name + DateTime.Now.ToString("ddMMyyyyHHmmss") + Path.GetExtension(file.FileName); using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await file.CopyToAsync(fileStream); } } book.BookPicture = path; bool isDelete = book.Chapters.Count > model.Chapters.Count; bool isAdd = model.Chapters.Count > book.Chapters.Count; int count = Math.Abs(model.Chapters.Count - book.Chapters.Count); int length = Math.Min(model.Chapters.Count, book.Chapters.Count); for (int i = 0; i < length; i++) { book.Chapters.ToList()[i].Name = model.Chapters[i]; } if (isDelete) { for (int i = length; i < length + count; i++) { Chapter c = book.Chapters.ToList()[i]; _systemContext.Entry(c).State = EntityState.Deleted; } } if (isAdd) { for (int i = length; i < length + count; i++) { book.Chapters.Add(new Chapter() { Book = book, Name = model.Chapters[i], NumberChapter = i }); } } _systemContext.SaveChanges(); return(RedirectToAction("Index")); } } return(View(model)); }
public void Update(TEntity obj) { Db.Entry(obj).State = System.Data.Entity.EntityState.Modified; Db.SaveChanges(); }
public virtual void Edit(T entity) { _context.Entry(entity).State = EntityState.Modified; }