示例#1
0
        public async Task <IActionResult> Create(SpecieCreateModel model)
        {
            DataResult <Specie> result = await _specieService.CreateSpecie(model);

            if (result.Success)
            {
                return(RedirectToAction("Details", new { result.Data.Id }));
            }

            if (result.ErrorCode == ErrorCode.UniquenessError)
            {
                await InstallViewBags();

                ModelState[nameof(model.Denomination)].Errors.Add("Such a record already exists");
                return(View("Create", model));
            }

            return(RedirectToAction("Error", "Error", new { result.ErrorCode, modelName = nameof(Specie) }));
        }
示例#2
0
        public async Task <Result> UpdateSpecie(int id, SpecieCreateModel model)
        {
            try
            {
                Specie entity = await _specieRepository.GetById(id);

                _mapper.MapUpdate(entity, model);

                return(await _specieRepository.Update(entity));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Problems with updating Specie by id : {id}");
                return(new Result
                {
                    Success = false,
                    ErrorCode = ErrorCode.InternalError,
                });
            }
        }
示例#3
0
        public async Task <DataResult <Specie> > CreateSpecie(SpecieCreateModel model)
        {
            try
            {
                DataResult <Specie> dataResult = await _specieRepository.Add(_mapper.MapBack(model));

                Result result = await _specieRepository
                                .Update(_mapper.MapUpdate(dataResult.Data, model));

                return(dataResult);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Problems with creating Specie");
                return(new DataResult <Specie>
                {
                    Success = false,
                    ErrorCode = ErrorCode.InternalError,
                });
            }
        }