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 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;
        }