Exemplo n.º 1
0
        public async Task <Result> UpdatePhylum(int id, PhylumModel model)
        {
            try
            {
                Phylum entity = await _phylumRepository.GetById(id);

                if (entity == null)
                {
                    return(new Result {
                        Success = false, ErrorCode = ErrorCode.NotFound,
                    });
                }

                return(await _phylumRepository.Update(_mapper.MapUpdate(entity, model)));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Problems with updating Phylum by id : {id}");
                return(new DataResult <PhylumModel>
                {
                    Success = false,
                    ErrorCode = ErrorCode.InternalError,
                });
            }
        }
Exemplo n.º 2
0
        public async Task <DataResult <PhylumModel> > GetPhylumById(int id)
        {
            try
            {
                Phylum entity = await _phylumRepository.GetById(id);

                if (entity == null)
                {
                    return(new DataResult <PhylumModel>
                    {
                        Success = false,
                        ErrorCode = ErrorCode.NotFound,
                    });
                }

                PhylumModel model = _mapper.Map(entity);

                return(new DataResult <PhylumModel>
                {
                    Success = true,
                    Data = model,
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Problems with getting Phylum by id : {id}");
                return(new DataResult <PhylumModel>
                {
                    Success = false,
                    ErrorCode = ErrorCode.InternalError,
                });
            }
        }
Exemplo n.º 3
0
        public async Task <DataResult <PhylumModel> > CreatePhylum(PhylumModel model)
        {
            try
            {
                Phylum entity = _mapper.MapBack(model);

                DataResult <Phylum> result = await _phylumRepository.Add(entity);

                return(new DataResult <PhylumModel>
                {
                    Success = result.Success,
                    ErrorCode = result.ErrorCode,
                    Data = _mapper.Map(result.Data),
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Problems with creating Phylum");
                return(new DataResult <PhylumModel>
                {
                    Success = false,
                    ErrorCode = ErrorCode.InternalError,
                });
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, PhylumModel model)
        {
            Result result = await _phylumService.UpdatePhylum(id, model);

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

            if (result.ErrorCode == ErrorCode.UniquenessError)
            {
                ModelState[nameof(model.Denomination)].Errors.Add("Such a record already exists");
                return(View("Edit", model));
            }

            return(RedirectToAction("Error", "Error", new { result.ErrorCode, modelName = nameof(Phylum) }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(PhylumModel model)
        {
            DataResult <PhylumModel> result = await _phylumService.CreatePhylum(model);

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

            if (result.ErrorCode == ErrorCode.UniquenessError)
            {
                ModelState[nameof(model.Denomination)].Errors.Add("Such a record already exists");
                return(View("Create", model));
            }

            return(RedirectToAction("Error", "Error", new { result.ErrorCode, modelName = nameof(Phylum) }));
        }