Esempio n. 1
0
        /// <summary>
        /// Cancel deal by ID
        /// </summary>
        /// <param name="sessioninfo"></param>
        /// <param name="DMKDealID"></param>
        /// <returns></returns>
        public static object CancellingDeal(SessionInfo sessioninfo, Guid DMKDealID)
        {
            ReconcileBusiness _reconcileBusiness = new ReconcileBusiness();
            DealBusiness _dealBusiness = new DealBusiness();
            List<DealTranModel> DealTrans = new List<DealTranModel>();
            DA_TRN deal = null;
            DA_TRN deal2 = null;
            List<DA_TRN> dealExts = null;
            string extdealno = string.Empty;
            try
            {
                LoggingHelper.Debug("Cancelling deal");
                //find deal before
                deal = _dealBusiness.GetByID(DMKDealID);
                if (deal == null)
                    return new { Result = "ERROR", Message = String.Format("Deal {0} is not found.", deal.INT_DEAL_NO) };

                if (deal.MA_PRODUCT.LABEL.Replace(" ", string.Empty) == ProductCode.FXSWAP.ToString())
                    deal2 = _dealBusiness.GetDealByProcessDate(sessioninfo.Process.CurrentDate).FirstOrDefault(p => p.INT_DEAL_NO == deal.INT_DEAL_NO && p.VERSION == deal.VERSION && p.ID != deal.ID);

                if (deal.MA_PRODUCT.LABEL.Replace(" ", string.Empty) == ProductCode.FXSWAP.ToString() && deal2 == null)
                    return new { Result = "ERROR", Message = String.Format("Deal {0} is not found.", deal.INT_DEAL_NO) };

                dealExts = _dealBusiness.GetByExternalByInternalDealNo(sessioninfo.Process.NextDate, deal.INT_DEAL_NO);
                if (dealExts == null)
                    return new { Result = "ERROR", Message = String.Format("OPICS Deal is not found.") };

               // extdealno = deal.EXT_DEAL_NO;

                deal.EXT_DEAL_NO = null;
                deal.EXT_PORTFOLIO = null;
                deal.STATUS_ID = _lookupvaluesRepository.StatusRepository.GetByLabel(StatusCode.OPEN.ToString()).ID;
                deal.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
                deal.LOG.MODIFYDATE = DateTime.Now;
                deal.INSERT_BY_EXT = null;
                DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), deal.MA_PRODUCT.LABEL.Replace(" ","")), Transaction = deal, UpdateStates = UpdateStates.Editing });

                if (deal2 != null)
                {
                    deal2.EXT_DEAL_NO = null;
                    deal2.EXT_PORTFOLIO = null;
                    deal2.STATUS_ID = _lookupvaluesRepository.StatusRepository.GetByLabel(StatusCode.OPEN.ToString()).ID;
                    deal2.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
                    deal2.LOG.MODIFYDATE = DateTime.Now;
                    deal2.INSERT_BY_EXT = null;
                    DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), deal2.MA_PRODUCT.LABEL.Replace(" ", "")), Transaction = deal2, UpdateStates = UpdateStates.Editing });
                }

                foreach (DA_TRN dealExt in dealExts)
                {
                    DealTrans.Add(new DealTranModel() { ProductTransaction = (ProductCode)Enum.Parse(typeof(ProductCode), dealExt.MA_PRODUCT.LABEL.Replace(" ", "")), Transaction = dealExt, UpdateStates = UpdateStates.Deleting });
                }

                _reconcileBusiness.UpdateDealReconcile(sessioninfo, DealTrans);

                LoggingHelper.Debug("End Cancelling deal");
                return new
                {
                    Result = "OK",
                    Message = String.Format("Process cancel the deal between DMK Deal no {0} and OPICS Deal no {1} completed", deal.INT_DEAL_NO, extdealno)
                };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }