public IActionResult PostStockPrice([FromBody] AddStockPriceModel sp)
        {
            ClaimsIdentity identity = HttpContext.User.Identity as ClaimsIdentity;
            string         role     = identity.FindFirst("Role").Value;

            if (role == "Admin")
            {
                var result = _repo.addStockPrice(sp);
                if (result)
                {
                    return(Ok(new Response {
                        Status = "Success", Message = "Stock Price Posted successfully"
                    }));
                }
                else
                {
                    return(BadRequest(new Response {
                        Status = "Failed", Message = "Stock Price creation unsuccessfully"
                    }));
                }
            }
            else
            {
                return(Unauthorized(new Response {
                    Status = "Failed", Message = "Stock Price creation unsuccessfully. Only Admins can create"
                }));
            }
        }
예제 #2
0
        public bool addStockPrice(AddStockPriceModel sp)
        {
            var        cmpany     = _db.Companies.Where(c => c.CompanyID == sp.CompanyCode).FirstOrDefault();
            StockPrice stockPrice = new StockPrice
            {
                CompanyCode = sp.CompanyCode,
                Company     = cmpany,
                Exchange    = sp.Exchange,
                price       = sp.price,
                Date        = sp.Date,
                Time        = sp.Time
            };
            var result = _db.StockPrices.Add(stockPrice);

            _db.SaveChanges();
            if (result != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }