Beispiel #1
0
        public IActionResult Create([FromBody] PortfolioModel portfolioModel)
        {
            try
            {
                if (portfolioModel == null)
                {
                    return(BadRequest("portfolio object is null"));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                var portfolio = _portfolioService.GetByISIN(portfolioModel.ISIN);
                if (portfolio != null)
                {
                    return(BadRequest("portfolio already exist"));
                }

                _portfolioService.Create(portfolioModel);
                return(CreatedAtRoute("GetByISIN", new { isin = portfolioModel.ISIN }, portfolioModel));
            }
            catch (Exception e)
            {
                return(StatusCode(500, "Internal server error"));
            }
        }
 public IActionResult Create(Portfolio portfolio)
 {
     if (ModelState.IsValid)
     {
         _portfolioService.Create(portfolio);
         _portfolioService.Commit();
         return(RedirectToAction("Index"));
     }
     return(View(portfolio));
 }
Beispiel #3
0
        public async Task <IActionResult> Post(PortfolioModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _portfolioService.Create(model);

            return(Ok(result));
        }
Beispiel #4
0
        public async Task <ActionResult <PortfolioRes> > Create([FromBody] SavePortfolioRes savePortfolioRes)
        {
            var validator        = new SavePortfolioValidator();
            var validationResult = await validator.ValidateAsync(savePortfolioRes);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var create = await _service.Create(_mapper.Map <SavePortfolioRes, Portfolio>(savePortfolioRes));

            var portfolio = await _service.GetById(create.UserId);

            var resource = _mapper.Map <Portfolio, PortfolioRes>(portfolio);

            return(Ok(resource));
        }
Beispiel #5
0
        // POST api/portfolio
        public HttpResponseMessage Post([FromBody] PortfolioDataType value)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.InternalServerError);

            if (!Object.Equals(null, value))
            {
                try
                {
                    PortfolioDataType cr = _portfolioService.Create(value);
                    response = Request.CreateResponse(HttpStatusCode.Created);
                    response.Headers.Location = new Uri(Url.Link("DefaultApi", new { shopperid = cr.ShopperID }));
                }
                catch (Exception e)
                {
                    ExceptionExtensions.LogError(e, "PortfolioController.Post(msdatatype)", "Error creating portfolio type from posted value");
                }
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            return(response);
        }