public void InsertSpendComment(SpendComments spendComments)
        {
            string sql = @"INSERT INTO [dbo].[spend_comments_statuses]
                           ([spend_id]
                           ,[comments]
                           ,[status]
                           ,[created_by_id])
                            VALUES
                            (@spendid
                           ,@comments
                           ,@status
                           ,@createdbyid)";

            DynamicParameters dp = new DynamicParameters();

            dp.Add("spendid", spendComments.SpendId, DbType.Int32, ParameterDirection.Input);
            dp.Add("comments", spendComments.Comments, DbType.String, ParameterDirection.Input);
            dp.Add("status", spendComments.Status.ToString(), DbType.String, ParameterDirection.Input);
            dp.Add("createdbyid", spendComments.CreatedById, DbType.Int32, ParameterDirection.Input);

            using (IDbConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                var affRowsX2 = conn.Execute(sql, dp);
            }
        }
Example #2
0
        public IHttpActionResult InsertSpendComment(SpendComments spendComments)
        {
            if (spendComments == null)
            {
                return(BadRequest("spend comments not found"));
            }

            if (spendComments.SpendId <= 0 || string.IsNullOrEmpty(spendComments.Comments))
            {
                return(BadRequest("Spend id and or comments not found"));
            }

            var loggedInUser = HttpContext.Current.User as SecurityPrincipal;

            logger.Info($"Spend Budget created by {loggedInUser.ForeName}");
            spendComments.CreatedById = loggedInUser.Id;

            _budgetService.InsertSpendComment(spendComments);
            return(Ok(spendComments));
        }
Example #3
0
        public IHttpActionResult TransferSpend(TransferSpendRequest transferSpendRequest)
        {
            if (!GuidConverter.IsValid(transferSpendRequest.TransferToBudgetReferenceId.ToString()))
            {
                return(BadRequest("From budget referenceid is missing."));
            }
            if (transferSpendRequest.TransferFromSpendId <= 0)
            {
                return(BadRequest("To spend id is missing."));
            }

            // Ensure we are not tranfering within the SAME budget
            var budgetTo = _budgetService.GetBudgetListResponse(transferSpendRequest.TransferToBudgetReferenceId);
            var found    = budgetTo.Spends.Where(sp => sp.Id == transferSpendRequest.TransferFromSpendId).FirstOrDefault();

            if (found != null)
            {
                return(BadRequest("Invalid request. You are trying to transer withing the same budget."));
            }

            var loggedInUser = HttpContext.Current.User as SecurityPrincipal;

            logger.Info($"Spend is transfered from spend id {transferSpendRequest.TransferFromSpendId} to budget {transferSpendRequest.TransferToBudgetReferenceId} by {loggedInUser.ForeName}");

            var inserted = _budgetService.TransferSpend(transferSpendRequest);
            // add comments
            SpendComments spendComments = new SpendComments()
            {
                SpendId     = transferSpendRequest.TransferFromSpendId,
                Comments    = transferSpendRequest.Comments,
                CreatedById = loggedInUser.Id,
                Status      = Status.Completed
            };

            _budgetService.InsertSpendComment(spendComments);

            return(Ok(inserted));
        }
 public void InsertSpendComment(SpendComments spendComments)
 {
     _spendDataProvider.InsertSpendComment(spendComments);
 }