Exemplo n.º 1
0
        public PostInvestmentDto AddInvestment(InvestmentDto investmentDto)
        {
            var response = new PostInvestmentDto { Success = false };
            try
            {
                Investment investment = new Investment();
                investment.Name = investmentDto.Name;
                investment.Type = investmentDto.Type;
                investment.DateCreated = System.DateTime.Now;
                investment.DateModified = System.DateTime.Now;
                investment.Active = 1;

                InvestmentLINQDataContext db = new InvestmentLINQDataContext();
                db.Investments.InsertOnSubmit(investment);
                db.SubmitChanges();

                //logic to add investment
                response.Investment = investmentDto;
                response.Success = true;
            }
            catch(System.Exception ex)
            {
                response.Message = ex.ToString();
                response.Investment = investmentDto;
                response.Success = false;
            }

            return response;
        }
Exemplo n.º 2
0
 public IHttpActionResult AddInvestment(InvestmentDto input)
 {
     try
     {
         InvestmentService _investmentService = new InvestmentService();
         var response = _investmentService.AddInvestment(input);
         return !response.Success
                    ? (IHttpActionResult)BadRequest(response.Message)
                    : (IHttpActionResult)Ok(response);
     }
     catch (Exception ex)
     {
         return InternalServerError(ex);
     }
 }
Exemplo n.º 3
0
        public IHttpActionResult DeleteInvestment(InvestmentDto input)
        {
            try
            {
                InvestmentService _investmentService = new InvestmentService();
                var response = _investmentService.DeleteInvestment(input);

                return !response.Success
                    ? (IHttpActionResult) BadRequest(response.Message)
                    : (IHttpActionResult) Ok(response);
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Exemplo n.º 4
0
        public ServiceResult UpdateInvestment(InvestmentDto investmentDto)
        {
            var response = new ServiceResult { Success = false };
            try
            {
                InvestmentLINQDataContext db = new InvestmentLINQDataContext();
                var item = db.Investments.Single(i => i.Id == investmentDto.Id);
                item.Name = investmentDto.Name;
                item.Type = investmentDto.Type;
                item.DateModified = System.DateTime.Now;
                db.SubmitChanges();

                response.Message = "Investment was updated successfully.";
                response.Success = true;
            }
            catch (System.Exception ex)
            {
                response.Message = ex.ToString();
                response.Success = false;
            }
            return response;
        }