private bool checkModelStateCreateEdit(ActionEnumForm action, inventory_receiving_model item) { if (string.IsNullOrEmpty(item.db.name)) { ModelState.AddModelError("db.name", "required"); } var search = repo.FindAll().Where(d => d.db.name == item.db.name && d.db.id != item.db.id).Count(); if (search > 0) { ModelState.AddModelError("db.name", "existed"); } if (item.db.type == null) { ModelState.AddModelError("db.type", "required"); } if (item.db.id_receiving_type == 0) { ModelState.AddModelError("db.id_receiving_type", "required"); } if (item.db.import_date == null) { ModelState.AddModelError("db.import_date", "required"); } if (item.db.id_warehouse == null) { ModelState.AddModelError("db.id_warehouse", "required"); } if (item.list_item.Count == 0) { ModelState.AddModelError("list_item", "required"); } return(ModelState.IsValid); }
public async Task <int> insert(inventory_receiving_model model) { model.db.status_del = 1; model.db.line_up_status = 1; await _context.inventory_receivings.AddAsync(model.db); _context.SaveChanges(); saveDetail(model); trigger(model.db.id); return(1); }
public int update(inventory_receiving_model model) { var db = _context.inventory_receivings.Where(d => d.id == model.db.id).FirstOrDefault(); db.name = model.db.name; db.type = model.db.type; db.update_by = model.db.update_by; db.update_date = model.db.update_date; db.import_date = model.db.import_date; db.id_receiving_type = model.db.id_receiving_type; db.object_ = model.db.object_; db.note = model.db.note; db.id_warehouse = model.db.id_warehouse; _context.SaveChanges(); saveDetail(model); trigger(model.db.id); return(1); }
public void saveDetail(inventory_receiving_model model) { var delete = _context.inventory_receiving_items.Where(t => t.id_inventory_receiving == model.db.id); _context.RemoveRange(delete); _context.SaveChanges(); model.list_item.ForEach(t => { t.db.id_warehouse = model.db.id_warehouse; t.db.id = 0; t.db.id_inventory_receiving = model.db.id; t.db.line_up_status = 1; if (t.db.conversion_factor == null) { t.db.conversion_factor = 1; } t.db.quantity_unit_main = t.db.quantity * t.db.conversion_factor; }); var listInsert = model.list_item.Select(d => d.db).ToList(); _context.inventory_receiving_items.AddRange(listInsert); _context.SaveChanges(); }
private bool checkModelStateCreateEdit(ActionEnumForm action, inventory_receiving_model item) { return(ModelState.IsValid); }
private bool checkModelStateEdit(inventory_receiving_model item) { return(checkModelStateCreateEdit(ActionEnumForm.edit, item)); }