public object Put(JObject updatedJSON)
        {
            object json;

            try
            {
                IDictionary <String, object> updated = updatedJSON.ToObject <IDictionary <String, object> >();

                User currentUser = UsersManager.GetCurrentUser(Request);

                string   messageError = "";
                Attached putting      = repository.Update(updated, currentUser.UserId, ref messageError);

                if (putting != null)
                {
                    json = new
                    {
                        total   = 1,
                        data    = putting,
                        success = true
                    };
                }
                else
                {
                    json = new
                    {
                        message = messageError,
                        success = false
                    };
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                json = new
                {
                    message = ex.Message,
                    success = false
                };
            };

            return(json);
        }
示例#2
0
        public bool Pay(int VendorId, string UserId, Payment Paid, ref string msg)
        {
            decimal       amount = 0, amountNB = 0, currencyRate = 0;
            string        reference = "";
            PaymentVendor payHeader = new PaymentVendor();

            payHeader.PayVendorCreatedBy   = UserId;
            payHeader.PayVendorCreatedDate = DateTime.Now;

            // Add into database pay Header
            payHeader = repPayHead.Add(payHeader, ref msg);

            //Insert into database details
            foreach (var pov in Paid.PaidDetail)
            {
                PaymentVendorDetail payDetail = new PaymentVendorDetail();
                payDetail.PayModeID                   = pov.PayModeID;
                payDetail.PayVendorId                 = payHeader.PayVendorId;
                payDetail.PayVendorDetailAmount       = pov.PayVendorDetailAmount;
                payDetail.PayVendorDetailAmountNB     = pov.PayVendorDetailAmountNB;
                payDetail.PayVendorDetailCurrencyRate = pov.PayVendorDetailCurrencyRate;
                payDetail.PayVendorDetailReference    = pov.PayVendorDetailReference;
                payDetail.AccountID                   = pov.AccountID;
                payDetail.PayVendorDetailDate         = pov.PayVendorDetailDate;
                payDetail.PayVendorDetailComments     = pov.PayVendorDetailComments;

                amount      += pov.PayVendorDetailAmount;
                amountNB    += pov.PayVendorDetailAmountNB;
                currencyRate = pov.PayVendorDetailCurrencyRate;
                reference   += "/" + pov.PayVendorDetailReference;

                payDetail = repPayDetail.Add(payDetail, ref msg);
            }

            // insert details to pay
            decimal thisPaid = 0, thisPaidNB = 0;

            foreach (var pov in Paid.POVList)
            {
                thisPaid   = pov.x_InvoiceVendorBalance.GetValueOrDefault();
                thisPaidNB = pov.x_InvoiceVendorBalanceNB.GetValueOrDefault();

                POVendorsDetail povDetail = new POVendorsDetail();
                povDetail.POVDetailAmount        = -thisPaid;
                povDetail.POVDetailAmountNB      = -thisPaidNB;
                povDetail.POVDetailCreatedBy     = UserId;
                povDetail.POVDetailCreatedDate   = DateTime.Now;
                povDetail.POVDetailCurrencyRate  = currencyRate;
                povDetail.POVDetailDate          = DateTime.Now;
                povDetail.POVDetailPaymentNumber = !string.IsNullOrEmpty(reference) ? reference.Substring(1) : reference;
                povDetail.POVId         = pov.POVId;
                povDetail.POVDetailType = "PB";
                povDetail.PayVendorId   = payHeader.PayVendorId;

                povDetail = repPOV.AddDetail(povDetail, ref msg);
            }

            foreach (var file in Paid.Files)
            {
                IDictionary <string, object> data = new Dictionary <string, object>();
                data["AttachId"]    = file.AttachId;
                data["AttachDirty"] = false;
                data["PayVendorId"] = payHeader.PayVendorId;
                repAtt.Update(data, UserId, ref msg);
            }
            //msg = String.Format("{0:#,###.00} and {1:#,###.00}", amount, amountNB);
            return(true);
        }