public void deleteDetailList(maintenance_system_device_model model) { var listDelete = _context.maintenance_system_device_list_details .Where(d => d.id_system_device == model.db.id) .Select(d => d).ToList(); _context.maintenance_system_device_list_details.RemoveRange(listDelete); _context.SaveChanges(); }
public int update(maintenance_system_device_model model) { var db = _context.maintenance_system_devices.Where(d => d.id == model.db.id).FirstOrDefault(); db.name = model.db.name; db.status_del = model.db.status_del; db.maintenance_period = model.db.maintenance_period; db.id_maintenance_system = model.db.id_maintenance_system; db.update_by = model.db.update_by; db.update_date = model.db.update_date; deleteDetailList(model); saveDetailList(model); _context.SaveChanges(); return(1); }
private void saveDetailList(maintenance_system_device_model model) { for (int i = 0; i < model.list_system_device_detail.Count(); i++) { _context.maintenance_system_device_list_details.Add(new maintenance_system_device_list_detail_db { id = 0, id_system_device = model.list_system_device_detail[i].db.id_system_device, id_system_device_detail = model.list_system_device_detail[i].db.id_system_device_detail, note = model.list_system_device_detail[i].db.note, quantity = model.list_system_device_detail[i].db.quantity, }); } _context.SaveChanges(); }
private bool checkModelStateCreateEdit(ActionEnumForm action, maintenance_system_device_model item) { if (string.IsNullOrEmpty(item.db.name)) { ModelState.AddModelError("db.name", "required"); } var searchName = repo.FindAll().Where(d => d.db.name == item.db.name && d.db.id != item.db.id).Count(); if (searchName > 0) { ModelState.AddModelError("db.name", "existed"); } return(ModelState.IsValid); }
public async Task <int> insert(maintenance_system_device_model model) { await _context.maintenance_system_devices.AddAsync(model.db); _context.SaveChanges(); var id_system_device = await _context.maintenance_system_devices.Where(t => t.name == model.db.name).Where(t => t.attach_device_name == model.db.attach_device_name).Select(t => t.id).SingleOrDefaultAsync(); if (model.list_system_device_detail.Count != 0) { for (int i = 0; i < model.list_system_device_detail.Count; i++) { model.list_system_device_detail[i].db.id = 0; model.list_system_device_detail[i].db.id_system_device = id_system_device; } saveDetailList(model); } _context.SaveChanges(); return(1); }
private bool checkModelStateEdit(maintenance_system_device_model item) { return(checkModelStateCreateEdit(ActionEnumForm.edit, item)); }