public void Create(Book book) { if (book == null) { return; } _context.Entry(book).State = EntityState.Added; book.Authors.ForEach(author => { if (author.AuthorId != 0) { _context.Entry(author).State = EntityState.Modified; } }); book.Genres.ForEach(genre => { if (genre.GenreId != 0) { _context.Entry(genre).State = EntityState.Modified; } }); _context.SaveChanges(); }
public virtual void Delete(TEntity entityToDelete) { if (context.Entry(entityToDelete).State == EntityState.Detached) { dbSet.Attach(entityToDelete); } dbSet.Remove(entityToDelete); }
public async Task <bool> PostNorms(string norm_ptvId, string NormsCount, string WarehouseCount, string onCar) { var norma_ptv = await _context.Norms_PTVs.AsNoTracking().FirstOrDefaultAsync(x => x.Norms_PTVId == int.Parse(norm_ptvId)); norma_ptv.NormsCount = int.Parse(NormsCount); norma_ptv.WarehouseNormsCount = decimal.Parse(WarehouseCount); norma_ptv.OnCar = bool.Parse(onCar); _context.Entry(norma_ptv).State = EntityState.Modified; await _context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Edit(Clothes clothes, int imgId) { if (_userManager.GetUserId(User) == adminId) { //if (ModelState.IsValid) //{ if (clothes.Image.ImageFile != null) { string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(clothes.Image.ImageFile.FileName); string extention = Path.GetExtension(clothes.Image.ImageFile.FileName); clothes.Image.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extention; string path = Path.Combine(wwwRootPath + "/Image/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { await clothes.Image.ImageFile.CopyToAsync(fileStream); } Image img = new Image { ImageName = clothes.Image.ImageName, Title = clothes.Image.Title }; await _context.Images.AddAsync(img); await _context.SaveChangesAsync(); clothes.Image = null; clothes.ImageId = _context.Images.FirstOrDefault(i => i.ImageName == img.ImageName).Id; _context.Entry(clothes).State = EntityState.Modified; await _context.SaveChangesAsync(); } else { clothes.ImageId = imgId; _context.Entry(clothes).State = EntityState.Modified; //_context.Add(clothes); await _context.SaveChangesAsync(); } //} //_context.Entry(clothes).State = EntityState.Modified; //await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } else { return(Permission()); } }
public static string AddUpdateContact(ContactInfo Info) { try { var ExistingContact = db.ContactInfo.Where(x => x.ID == Info.ID).FirstOrDefault(); if (ExistingContact == null) { db.ContactInfo.Add(Info); db.SaveChanges(); return("1"); } else { ExistingContact.firstName = Info.firstName; ExistingContact.lastName = Info.lastName; ExistingContact.Email = Info.Email; ExistingContact.PhoneNumber = Info.PhoneNumber; ExistingContact.isActive = Info.isActive; db.Entry(ExistingContact).State = EntityState.Modified; db.SaveChanges(); return("2"); } } catch (Exception ex) { Logging.Logging.WriteErrorLog(ex); return("0"); } }
public bool Modify(SysRole entity, string qx) { if (entity == null) { return(false); } if (entity.ID == 0) { return(false); } var old_entity = db.SysRoles.Find(entity.ID); db.Entry(old_entity).CurrentValues.SetValues(entity); //修改权限数据 if (string.IsNullOrWhiteSpace(qx)) { db.SysRoleRoutes.Where(p => p.SysRoleID == entity.ID).ToList().ForEach(p => db.Entry(p).State = System.Data.Entity.EntityState.Deleted); } List <int> new_id_list = qx.Split(',').Select(Int32.Parse).ToList(); var route_list = db.SysRoleRoutes.Where(p => p.SysRoleID == entity.ID).ToList(); List <int> route_id_list = new List <int>(); foreach (var item in route_list) { route_id_list.Add(item.SysRouteID); } //判断存在的差 var route_del_list = route_id_list.Except(new_id_list).ToList(); foreach (var item in route_del_list) { //删除 var del_entity = db.SysRoleRoutes.Where(p => p.SysRouteID == item && p.SysRoleID == entity.ID).FirstOrDefault(); db.SysRoleRoutes.Remove(del_entity); } var route_add_list = new_id_list.Except(route_id_list).ToList(); foreach (var item in route_add_list) { //做增加 db.SysRoleRoutes.Add(new SysRoleRoute() { SysRoleID = entity.ID, SysRouteID = item }); } try { db.SaveChanges(); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) { throw new Exception("保存测试信息失败", ex); } return(true); }
public ActionResult Edit([Bind(Include = "ID,Name,Email,Address,Phone,Urgent")] Client client) { if (ModelState.IsValid) { db.Entry(client).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(client)); }
public ActionResult Edit([Bind(Include = "CategoryID,CategoryName")] Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public void SaveDirectory(Directory directory) { if (directory.Id == 0) { context.Directory.Add(directory); } else { context.Entry(directory).State = EntityState.Modified; } }
public ActionResult Edit([Bind(Include = "SubCategoryID,SubCategoryName,CategoryID")] SubCategory subCategory) { if (ModelState.IsValid) { db.Entry(subCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Category, "CategoryID", "CategoryName", subCategory.CategoryID); return(View(subCategory)); }
public void SaveMaterial(Material material) { if (material.Id == 0) { context.Material.Add(material); } else { context.Entry(material).State = EntityState.Modified; } }
public void SaveAuthor(Author author) { if (author.Id == 0) { context.author.Add(author); } else { context.Entry(author).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public async Task SaveRank(Rank rank) { if (rank.RankId == 0) { await _context.Ranks.AddAsync(rank); } else { _context.Entry(rank).State = EntityState.Modified; } await _context.SaveChangesAsync(); }
public void SaveMaterial(Material m) { if (m.Id == 0) { _context.Materials.Add(m); } else { _context.Entry(m).State = EntityState.Modified; } _context.SaveChanges(); }
public void SaveDirectory(Directory achieve) { if (achieve.Id == 0) { context.Directories.Add(achieve); } else { context.Entry(achieve).State = EntityState.Modified; } context.SaveChanges(); }
public void SaveCustomer(Customer customer) { if (customer.Id == 0) { context.Customers.Add(customer); } else { context.Entry(customer).State = EntityState.Modified; } context.SaveChanges(); }
public async Task SavePosition(Position position) { if (position.PositionId == 0) { _context.Positions.Add(position); } else { _context.Entry(position).State = EntityState.Modified; } await _context.SaveChangesAsync(); }
public void SaveProduct(Product product) { if (product.Id == 0) { context.Products.Add(product); } else { context.Entry(product).State = EntityState.Modified; } context.SaveChanges(); }
public void SaveProperties(Properties prop) { if (prop.Id == 0) { context.Properties.Add(prop); } else { context.Entry(prop).State = EntityState.Modified; } context.SaveChanges(); }
public void SaveDirectory(Directory dir) { if (dir.Id == 0) { _context.Directories.Add(dir); } else { _context.Entry(dir).State = EntityState.Modified; } _context.SaveChanges(); }
public void SaveLog(Log log) { if (log.Id == 0) { context.log.Add(log); } else { context.Entry(log).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveCode(Code code) { if (code.Id == 0) { context.Codes.Add(code); } else { context.Entry(code).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveDirectory(Directory directory) { if (directory.Id == 0) { context.Directory.Add(directory).State = Microsoft.EntityFrameworkCore.EntityState.Added; } else { context.Entry(directory).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveOrder(Order order) { if (order.Id == 0) { context.Orders.Add(order); } else { context.Entry(order).State = EntityState.Modified; } context.SaveChanges(); }
public async Task SaveDepartment(Department department) { if (department.DepartmentId == 0) { _context.Departments.Add(department); } else { _context.Entry(department).State = EntityState.Modified; } await _context.SaveChangesAsync(); }
public async Task SaveFired(Fired Fired) { if (Fired.FiredId == 0) { await _context.Fireds.AddAsync(Fired); } else { _context.Entry(Fired).State = EntityState.Modified; } await _context.SaveChangesAsync(); }
public void SaveCategory(Category arhieve) { if (arhieve.Id == 0) { _context.Categories.Add(arhieve); } else { _context.Entry(arhieve).State = EntityState.Modified; } _context.SaveChanges(); }
public void SaveBook(Content book) { if (book.Id == 0) { context.Books.Add(book); } else { context.Entry(book).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveMaterial(Material material) { if (material.Id == 0) { context.Material.Add(material); } else { context.Entry(material).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } context.SaveChanges(); }
public void SaveProductProperties(ProductProperties PP) { if (PP.Id == 0) { context.ProductProperties.Add(PP); } else { context.Entry(PP).State = EntityState.Modified; } context.SaveChanges(); }