Ejemplo n.º 1
0
        public async Task <Machine> Create(Machine entity)
        {
            await _context.Set <Machine>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
Ejemplo n.º 2
0
        public async Task <T> Create(T entity)
        {
            await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
Ejemplo n.º 3
0
        public async Task <Operation> Create(Operation entity)
        {
            await _context.Set <Operation>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
        public async Task <ProductionLine> Create(ProductionLine entity)
        {
            await _context.Set <ProductionLine>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
        public async Task <IActionResult> Create([Bind("RouteID,LineID,BuggyID")] RouteModel routeModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(routeModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BuggyID"] = new SelectList(_context.Buggies, "BuggyID", "BuggyID", routeModel.BuggyID);
            ViewData["LineID"]  = new SelectList(_context.Lines, "ID", "ID", routeModel.LineID);
            return(View(routeModel));
        }
Ejemplo n.º 6
0
        private async Task <RfidEvent> CreateRfidEvent(int rfid, string eventType)
        {
            var r = new RfidEvent
            {
                Rfid      = rfid,
                EventType = eventType,
                StartUtc  = _now
            };

            _context.RfidEvents.Add(r);
            await _context.SaveChangesAsync();

            return(r);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates new Maintenance Task to db
        /// </summary>
        /// <param name="task">Task to create</param>
        /// <returns>Created MaintenanceTask</returns>
        public async Task <MaintenanceTask> Create(MaintenanceTask task)
        {
            try {
                var fdExists = await _context.FactoryDevices.AnyAsync(fd => fd.Id == task.FactoryDeviceId);

                if (fdExists)
                {
                    _context.MaintenanceTasks.Add(task);
                    await _context.SaveChangesAsync();

                    return(task);
                }
                return(null);
            } catch (Exception e) {
                throw e;
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Name")] LineModel lineModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(lineModel);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(lineModel));
        }
        public async Task <ActionResult> Post([FromBody] RfidTagViewModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Tag))
            {
                return(BadRequest("Tag cannot be empty."));
            }

            var rfid = await _context.Rfids.FirstOrDefaultAsync(r => r.Tag == model.Tag);

            if (rfid != null)
            {
                return(Ok());
            }

            _context.Rfids.Add(new Rfid {
                Tag = model.Tag
            });
            if (0 < await _context.SaveChangesAsync())
            {
                return(Ok());
            }

            return(BadRequest("Couldn't create tag and I think it's something you did."));
        }