public IActionResult PostIPO([FromBody] AddIPOModel ipo)
        {
            ClaimsIdentity identity = HttpContext.User.Identity as ClaimsIdentity;
            string         role     = identity.FindFirst("Role").Value;

            if (role == "Admin")
            {
                var result = _repo.addIPO(ipo);
                if (result)
                {
                    return(Ok(new Response {
                        Status = "Success", Message = "IPO Posted successfully"
                    }));
                }
                else
                {
                    return(BadRequest(new Response {
                        Status = "Failed", Message = "IPO creation unsuccessfully"
                    }));
                }
            }
            else
            {
                return(Unauthorized(new Response {
                    Status = "Failed", Message = "IPO creation unsuccessfully. Only Admins can create"
                }));
            }
        }
Exemple #2
0
        public bool addIPO(AddIPOModel model)
        {
            var        company = _db.Companies.Where(c => c.CompanyID == model.CompanyID).FirstOrDefault();
            IPODetails ipo     = new IPODetails
            {
                CompanyID            = model.CompanyID,
                Company              = company,
                stockExchanges       = model.stockExchanges,
                PricePerShare        = model.PricePerShare,
                TotalAvailableShares = model.TotalAvailableShares,
                OpeningDate          = model.OpeningDate,
                Remarks              = model.Remarks
            };
            var result = _db.IPODetails.Add(ipo);

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