Beispiel #1
0
        public async Task <IActionResult> AddPosition([FromBody] CreatePositionDto createPosition)
        {
            if (createPosition == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (await _positionService.PosNameIsEixst(createPosition.Name))
            {
                return(BadRequest("职业名称已存在"));
            }
            if (await _positionService.PosNumIsEixst(createPosition.PositionNum))
            {
                return(BadRequest("职业编号已存在"));
            }
            var pos = _mapper.Map <Position>(createPosition);

            _positionService.AddT(pos);
            if (!await _positionService.Save())
            {
                return(StatusCode(500, "添加职位信息时出错"));
            }
            return(Created("", createPosition));
        }
 public IHttpActionResult Create([FromBody] CreatePositionDto position)
 {
     if (position == null)
     {
         return(BadRequest());
     }
     if (!ModelState.IsValid)
     {
         string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
         return(BadRequest(errorMessage));
     }
     try
     {
         _positionService.Create(position);
     }
     catch (LogicalException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
     }
     return(Ok());
 }
        public void Create(CreatePositionDto dto)
        {
            Position position = this.mapper.Map <Position>(dto);

            this.dbContext.Positions.Add(position);

            this.dbContext.SaveChanges();
        }
Beispiel #4
0
        public void Create(CreatePositionDto dto)
        {
            var position = new Position
            {
                WorkUnitId = dto.WorkUnitId,
                Title      = dto.Title
            };

            _positionRepository.Insert(position);
        }
        public IActionResult Create(CreatePositionInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Error", "Home"));
            }

            CreatePositionDto position = this.mapper.Map <CreatePositionDto>(model);

            this.positionService.Create(position);

            return(this.RedirectToAction("All", "Positions"));
        }
Beispiel #6
0
        public async Task <IActionResult> CreatePosition([FromBody] CreatePositionDto createPositionDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId    = User.GetUserId();
            var portfolio = await _unitOfWork.PortfolioRepository.GetPortfolioWithPositionsAsync(createPositionDto.PortfolioId);

            if (portfolio.AppUserId != userId)
            {
                return(Unauthorized("You are not authorized to add a position to this portfolio."));
            }

            foreach (var p in portfolio.Positions)
            {
                if (p.Ticker == createPositionDto.Ticker)
                {
                    return(BadRequest("Ticker symbol is already present in the portfolio."));
                }
            }

            createPositionDto.Ticker = createPositionDto.Ticker.ToUpper();

            var position = _mapper.Map <Position>(createPositionDto);

            position.CostBasis = position.Shares * position.PricePerShare;
            if (position.CommissionFee != null)
            {
                position.CostBasis = (decimal)(position.CostBasis + position.CommissionFee);
            }

            await _unitOfWork.PositionRepository.CreatePosition(position);

            if (await _unitOfWork.Complete())
            {
                return(CreatedAtRoute("GetPositionByIdAsync", new { id = position.Id }, position));
            }
            return(BadRequest());
        }