Ejemplo n.º 1
0
        public async Task <IResultModel> Add(AreaAddModel model)
        {
            var entity = _mapper.Map <AreaEntity>(model);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.HasExists);
            }

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
Ejemplo n.º 2
0
        public async Task <IResultModel> Add(AreaAddModel model)
        {
            var entity = _mapper.Map <AreaEntity>(model);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.HasExists);
            }

            entity.Pinyin  = NPinyin.Pinyin.GetPinyin(entity.Name);
            entity.Jianpin = NPinyin.Pinyin.GetInitials(entity.Name);

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
Ejemplo n.º 3
0
        public async Task <(HttpStatusCode statusCode, string areaDisplayId)> CreateArea(AreaDto areaToAdd)
        {
            _logger.LogInformation($"Service-CreateArea-Executing CreateArea started at {DateTime.UtcNow}");

            var areaDisplayId = string.Empty;
            var statusCode    = HttpStatusCode.Created;

            var areaSpec = new AreaWithAreaOwnersSpecification(areaToAdd.AreaName, false);

            var area = (await _areaRepository.ListAsync(areaSpec).ConfigureAwait(false)).FirstOrDefault();

            if (area != null)
            {
                _logger.LogInformation($"Area with area name {areaToAdd.AreaName} already exists!!!");
                statusCode = HttpStatusCode.BadRequest;
            }
            else
            {
                Area areaEntity = await _areaRepository.GetMaxOfPrimaryKey();

                areaToAdd.AreaDisplayId = areaEntity.GetNextPrimaryKey();
                await _areaRepository.AddAsync(areaToAdd.ToEntity(true)).ConfigureAwait(false);

                await _areaRepository.SaveAllwithAudit().ConfigureAwait(false);

                statusCode    = HttpStatusCode.OK;
                areaDisplayId = areaToAdd.AreaDisplayId;
            }

            _logger.LogInformation($"Service-GetAreaByName-Executing CreateArea completed at {DateTime.UtcNow}");

            return(statusCode, areaDisplayId);
        }