Esempio n. 1
0
        //改
        public async Task <bool> UpdateAsync(CameraPathDto dto)
        {
            //这一句话使用了linq
            var entity = _context.CameraPaths.FirstOrDefault(u => u.Id == dto.Id);

            _mapper.Map(dto, entity);
            return(await _context.SaveChangesAsync() > 0);
        }
Esempio n. 2
0
        //增
        public async Task <string> AddAsync(CameraPathDto dto)
        {
            var entity = _mapper.Map <CameraPathDto, CameraPathEntity>(dto);

            entity.Init();
            _context.CameraPaths.Add(entity);
            return(await _context.SaveChangesAsync() > 0 ? entity.Id : string.Empty);
        }
Esempio n. 3
0
        public async Task <IActionResult> Add(CameraPathDto dto)
        {
            if (ModelState.IsValid)
            {
                var result = await _cameraPathService.AddAsync(dto);

                if (result.IsNotBlank())
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(dto));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(CameraPathDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(View(dto));
            }
            var result = await _cameraPathService.UpdateAsync(dto);

            if (result)
            {
                return(RedirectToAction("Index"));
            }
            return(View(dto));
        }