Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Name, IsCore,CategoryId")] DeviceModel model)
        {
            if (ModelState.IsValid)
            {
                await _modelsRepository.AddAsync(model);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Esempio n. 2
0
        public async Task <ModelDto> AddModelAsync(int accountId, ModelDto model)
        {
            Guard.AgainstNull(model, "model");
            Guard.AgainstAccountNumberMismatch(accountId, model.AccountId, "accountId", "model.AccountId");
            var modelEntity = _mapper.Map <ModelDto, Model>(model);

            try
            {
                await _modelRepository.AddAsync(modelEntity);

                _logger.LogInformation($"Added model, new Id = {modelEntity.Id}");
                return(await GetModelByIdAsync(accountId, modelEntity.Id));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error adding model: {model}.");
                return(null);
            }
        }
Esempio n. 3
0
 public Task AddAsync(TDto dto) =>
 _repository.AddAsync(_mapper.Map <TModel>(dto), m => m.Id.Equals(dto.Id));