Пример #1
0
        /// <summary>
        /// validate input data confirm and register data into database
        /// </summary>
        /// <returns></returns>
        public ActionResult ICS031_Confirm()
        {
            ICS031_ScreenParameter param        = GetScreenObject <ICS031_ScreenParameter>();
            ICS031_RegisterData    RegisterData = new ICS031_RegisterData();
            CommonUtil             comUtil      = new CommonUtil();

            // reuse param that send on Register Click
            if (param != null)
            {
                RegisterData = param.RegisterData;
            }

            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            ObjectResultData resByIssue   = new ObjectResultData();
            ObjectResultData resByInvoice = new ObjectResultData();

            tbt_DebtTarget doTbt_DebtTarget = new tbt_DebtTarget();

            try
            {
                // Common Check Sequence

                // System Suspend
                ICommonHandler handlerCommon  = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                IIncomeHandler iincomeHandler = ServiceContainer.GetService <IIncomeHandler>() as IIncomeHandler;

                if (handlerCommon.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }


                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        #region tbt_DebtTarget
                        // Comment by Jirawat Jannet @ 2016-10-13
                        //for (int i = 0; i < RegisterData.Detail1.Count; i++)
                        //{
                        //    doTbt_DebtTarget = new tbt_DebtTarget();
                        //    doTbt_DebtTarget.BillingOfficeCode = RegisterData.Detail1[i].txtBillingOfficeCode;

                        //    doTbt_DebtTarget.AmountAll = (decimal?)Convert.ToDecimal(RegisterData.Detail1[i].txtAmountAll);
                        //    doTbt_DebtTarget.DetailAll = (int?)Convert.ToInt32(RegisterData.Detail1[i].txtDetailAll);
                        //    doTbt_DebtTarget.Amount2Month = (decimal?)Convert.ToDecimal(RegisterData.Detail1[i].txtAmount2Month);
                        //    doTbt_DebtTarget.Detail2Month = (int?)Convert.ToInt32(RegisterData.Detail1[i].txtDetail2Month);
                        //    if (iincomeHandler.UpdateTbt_DebtTarget(doTbt_DebtTarget) == 0)
                        //    {
                        //        throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7121, null);
                        //    }
                        //}
                        #endregion

                        // add by Jirawat jannet @ 2016-10-13
                        #region tbt_DebtTarget edit by Jirawat Jannet

                        string currencyLocal = MiscellaneousTypeCommon.getCurrencyName(CurrencyUtil.C_CURRENCY_LOCAL);
                        string currencyUs    = MiscellaneousTypeCommon.getCurrencyName(CurrencyUtil.C_CURRENCY_US);

                        foreach (var g in RegisterData.Detail1.GroupBy(m => m.txtBillingOfficeCode).Select(m => m.Key))
                        {
                            var local = RegisterData.Detail1.Where(m => m.txtBillingOfficeCode == g && m.txtCurrency == currencyLocal).First();
                            var us    = RegisterData.Detail1.Where(m => m.txtBillingOfficeCode == g && m.txtCurrency == currencyUs).First();

                            doTbt_DebtTarget = new tbt_DebtTarget();
                            doTbt_DebtTarget.BillingOfficeCode = local.txtBillingOfficeCode;

                            doTbt_DebtTarget.AmountAll    = (decimal?)Convert.ToDecimal(local.txtAmountAll);
                            doTbt_DebtTarget.DetailAll    = (int?)Convert.ToInt32(local.txtDetailAll);
                            doTbt_DebtTarget.Amount2Month = (decimal?)Convert.ToDecimal(local.txtAmount2Month);
                            doTbt_DebtTarget.Detail2Month = (int?)Convert.ToInt32(local.txtDetail2Month);

                            doTbt_DebtTarget.AmountAllUsd    = (decimal?)Convert.ToDecimal(us.txtAmountAll);
                            doTbt_DebtTarget.DetailAllUsd    = (int?)Convert.ToInt32(us.txtDetailAll);
                            doTbt_DebtTarget.Amount2MonthUsd = (decimal?)Convert.ToDecimal(us.txtAmount2Month);
                            doTbt_DebtTarget.Detail2MonthUsd = (int?)Convert.ToInt32(us.txtDetail2Month);

                            if (iincomeHandler.UpdateTbt_DebtTarget(doTbt_DebtTarget) == 0)
                            {
                                throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7121, null);
                            }
                        }

                        #endregion



                        scope.Complete();
                    }
                    catch (Exception ex)
                    {
                        // Fail rollback all record
                        scope.Dispose();
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        res.AddErrorMessage(ex);
                        return(Json(res));
                    }
                }


                // return "1" to js is every thing OK
                if (res.MessageList == null || res.MessageList.Count == 0)
                {
                    res.ResultData = "1";
                }
                else
                {
                    res.ResultData = "0";
                }
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }