Esempio n. 1
0
        private bool checkModelStateCreateEdit(ActionEnumForm action, sys_item_model item)
        {
            if (string.IsNullOrEmpty(item.db.code_item))
            {
                ModelState.AddModelError("db.code_item", "required");
            }
            if (string.IsNullOrEmpty(item.db.name))
            {
                ModelState.AddModelError("db.name", "required");
            }
            if (item.db.type == null)
            {
                ModelState.AddModelError("db.type", "required");
            }
            if (string.IsNullOrEmpty(item.db.id_item_type))
            {
                ModelState.AddModelError("db.id_item_type", "required");
            }
            if (string.IsNullOrEmpty(item.db.id_unit))
            {
                ModelState.AddModelError("db.id_unit", "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");
            }


            return(ModelState.IsValid);
        }
Esempio n. 2
0
        public int update(sys_item_model model)
        {
            var db = _context.sys_items.Where(d => d.id == model.db.id).FirstOrDefault();

            db.name            = model.db.name;
            db.note            = model.db.note;
            db.price           = model.db.price;
            db.max_stock       = model.db.max_stock;
            db.min_stock       = model.db.min_stock;
            db.other_parameter = model.db.other_parameter;
            db.long_           = model.db.long_;
            db.wide            = model.db.wide;
            db.high            = model.db.high;
            db.outside_radius  = model.db.outside_radius;
            db.inside_radius   = model.db.inside_radius;
            db.id_item_type    = model.db.id_item_type;
            db.id_unit         = model.db.id_unit;
            db.id_cost_type    = model.db.id_cost_type;
            db.type            = model.db.type;
            db.update_by       = model.db.update_by;
            db.update_date     = model.db.update_date;
            db.code_item       = model.db.code_item;
            _context.SaveChanges();
            saveDetail(model);
            return(1);
        }
Esempio n. 3
0
        public void saveDetail(sys_item_model model)
        {
            var delete1 = _context.sys_item_unit_others.Where(t => t.id_item == model.db.id);

            _context.RemoveRange(delete1);
            _context.SaveChanges();
            model.listsys_item_unit_other.ForEach(t =>
            {
                t.db.id      = 0;
                t.db.id_item = model.db.id;
            });
            var listInsert1 = model.listsys_item_unit_other.Select(d => d.db).ToList();

            _context.sys_item_unit_others.AddRange(listInsert1);
            _context.SaveChanges();



            var delete = _context.sys_item_min_max_stocks.Where(t => t.id_item == model.db.id);

            _context.RemoveRange(delete);
            _context.SaveChanges();
            model.list_item_min_max_stock.ForEach(t =>
            {
                t.db.id      = 0;
                t.db.id_item = model.db.id;
            });
            var listInsert = model.list_item_min_max_stock.Select(d => d.db).ToList();

            _context.sys_item_min_max_stocks.AddRange(listInsert);
            _context.SaveChanges();
        }
Esempio n. 4
0
        public async Task <int> insert(sys_item_model model)
        {
            await _context.sys_items.AddAsync(model.db);

            _context.SaveChanges();
            saveDetail(model);
            return(1);
        }
Esempio n. 5
0
 private bool checkModelStateEdit(sys_item_model item)
 {
     return(checkModelStateCreateEdit(ActionEnumForm.edit, item));
 }