public void saveCheckList(maintenance_process_model model)
        {
            for (int i = 0; i < model.list_check_list.Count(); i++)
            {
                model.list_check_list[i].id = 0;
                var newDb = new maintenance_process_checklist_detail_db()
                {
                    create_by             = model.list_check_list[i].create_by,
                    create_date           = DateTime.Now,
                    device_information    = model.list_check_list[i].device_information,
                    evaluated_information = model.list_check_list[i].evaluated_information,
                    id_maintenance_schedual_system_device = model.db.id,
                    id_maintenance_system        = model.db.id_maintenance_system,
                    id_maintenance_system_device = model.db.id_maintenance_system_device,
                    note                      = model.list_check_list[i].note,
                    status_del                = model.list_check_list[i].status_del,
                    status_maintenance        = model.list_check_list[i].status_maintenance,
                    times                     = model.db.times,
                    estimate_maintenance_date = model.db.estimate_maintenance_date,
                    id = 0,
                };
                _context.maintenance_process_checklist_details.Add(newDb);
            }

            _context.SaveChanges();
        }
Exemplo n.º 2
0
        private bool checkModelStateCreateEdit(ActionEnumForm action, maintenance_process_model item)
        {
            if (string.IsNullOrEmpty(item.db.name))
            {
                ModelState.AddModelError("db.name", "required");
            }
            if (item.db.start_time == default(DateTime))
            {
                ModelState.AddModelError("db.start_time", "required");
            }
            if (item.db.end_time == default(DateTime))
            {
                ModelState.AddModelError("db.start_time", "required");
            }

            var searchName = repo._context.maintenance_processes.Where(d =>
                                                                       d.name == item.db.name && d.id != item.db.id).Count();

            if (searchName > 0)
            {
                ModelState.AddModelError("db.name", "existed");
            }

            return(ModelState.IsValid);
        }
        public void deleteListPeople(maintenance_process_model model)
        {
            var listDelete = _context.maintenance_process_peoples
                             .Where(d => d.id_maintenance_process == model.db.id)
                             .Select(d => d).ToList();

            _context.maintenance_process_peoples.RemoveRange(listDelete);
            _context.SaveChanges();
        }
        public void deleteCheckList(maintenance_process_model model)
        {
            var listDelete = _context.maintenance_process_checklist_details
                             .Where(d => d.id_maintenance_system == model.db.id_maintenance_system)
                             .Where(d => d.id_maintenance_system_device == model.db.id_maintenance_system_device)
                             .Where(d => d.times == model.db.times)
                             .Select(d => d).ToList();

            _context.maintenance_process_checklist_details.RemoveRange(listDelete);
            _context.SaveChanges();
        }
        public void saveListPeople(maintenance_process_model model)
        {
            for (int i = 0; i < model.list_people.Count(); i++)
            {
                var newDb = new maintenance_process_people_db()
                {
                    create_by              = model.list_people[i].db.create_by,
                    create_date            = DateTime.Now,
                    id_maintenance_process = model.db.id,
                    id_people              = model.list_people[i].db.id_people,
                    note       = model.list_people[i].db.note,
                    status_del = 1,
                    id         = 0,
                };
                _context.maintenance_process_peoples.Add(newDb);
            }

            _context.SaveChanges();
        }
        public async Task <int> insert(maintenance_process_model model)
        {
            model.db.status_del         = 1;
            model.db.status_maintenance = 2;
            long id_maintenance_schedual_system_device = model.db.id;

            model.db.id_schedual_system_device = id_maintenance_schedual_system_device;
            model.db.id = 0;
            await _context.maintenance_processes.AddAsync(model.db);

            // changeStatusMaintenance(id_maintenance_schedual_system_device);


            _context.SaveChanges();
            saveCheckList(model);
            saveListPeople(model);

            return(1);
        }
        public int update(maintenance_process_model model)
        {
            var db = _context.maintenance_schedual_system_devices
                     .Where(d => d.id == model.db.id)
                     .Where(d => d.id_maintenance_system == model.db.id_maintenance_system)
                     .Where(d => d.id_maintenance_system_device == model.db.id_maintenance_system_device)
                     .Where(d => d.id_factory == model.db.id_factory)
                     .Where(d => d.id_factory_line == model.db.id_factory_line)
                     .Where(d => d.id_planning == model.db.id_planning)
                     .Where(d => d.times == model.db.times).Select(d => d).SingleOrDefault();

            db.status_maintenance = 2;
            deleteCheckList(model);
            saveCheckList(model);
            deleteListPeople(model);
            saveListPeople(model);
            _context.SaveChanges();
            return(1);
        }
Exemplo n.º 8
0
 private bool checkModelStateEdit(maintenance_process_model item)
 {
     return(checkModelStateCreateEdit(ActionEnumForm.edit, item));
 }