Exemple #1
0
        public (bool, int) InsertNewIPODetail(IPODetailsDto ipo_dto)
        {
            var existing_company = company_service.GetExistingCompany(ipo_dto.RegisteredCompanyId);

            if (existing_company == null)
            {
                return(false, 1);
            }

            var existing_stockexchange = se_service.GetExistingStockExchange(ipo_dto.RegisteredStockExchangeId);

            if (existing_stockexchange == null)
            {
                return(false, 2);
            }

            var ipo = new IPODetails
            {
                PricePerShare           = ipo_dto.PricePerShare,
                TotalShares             = ipo_dto.TotalShares,
                OfferingDateTime        = Convert.ToDateTime(ipo_dto.OfferingDate + " " + ipo_dto.OfferingTime),
                Remarks                 = ipo_dto.Remarks,
                RegisteredCompany       = existing_company,
                RegisteredStockExchange = existing_stockexchange
            };

            bool add_company_se_relationship =
                se_service.AddRelationshipWithCompany(new JoinCompanyStockExchange
            {
                Company = existing_company, StockExchange = existing_stockexchange
            });

            if (!add_company_se_relationship)
            {
                return(false, 3);
            }

            bool added = repository.Add(ipo);

            return(added, 0);
        }
 public IActionResult Post([FromBody] IPODetailsDto entity)
 {
     if (ModelState.IsValid)
     {
         var new_item = new IPODetails
         {
             PricePerShare       = entity.pricePerShare,
             TotalNumberOfShares = entity.totalNumberShares,
             OpenDateTime        = Convert.ToDateTime(entity.date + " " + entity.time),
             Remarks             = entity.remarks,
             CompanyId           = entity.companyId,
             StockExchangeId     = entity.stockExchangeId
         };
         var isAdded = repository.add(new_item);
         if (isAdded)
         {
             return(Created("IPODETAILS", new_item));
         }
     }
     return(BadRequest(ModelState));
 }
        public IActionResult PostAddCompanyIPO(IPODetailsDto ipo_dto)
        {
            if (ModelState.IsValid)
            {
                (bool isAdded, int status) = ipo_service.InsertNewIPODetail(ipo_dto);
                if (status == 1)
                {
                    return(NotFound("Company not found"));
                }
                if (status == 2)
                {
                    return(NotFound("Stock Exchange not found"));
                }

                if (isAdded)
                {
                    return(Created("Added new IPO details", ipo_dto));
                }
                return(StatusCode(500, "Internal server error"));
            }
            return(BadRequest(ModelState));
        }
 public void Put(int id, IPODetailsDto IPODetail) //to update
 {
     // check if the IPO exists and only then update -> do this via IPORepository
     repository.Update(IPODetail);
 }
 public void Post(IPODetailsDto IPODetail) //to add IPO Details of a company
 {
     var x = repository.Add(IPODetail);
 }