public static object Create(MA_INSTRUMENT record)
        {
            ILookupValuesRepository _lookupvaluesRepository = RepositorySesssion.GetRepository();

            record.PRODUCT_ID = _lookupvaluesRepository.ProductRepository.GetByLabel(ProductCode.BOND.ToString()).ID;

            return InstrumentUIP.Create(SessionInfo, record);
        }
        public MA_INSTRUMENT Create(SessionInfo sessioninfo, MA_INSTRUMENT instrument, ProductCode product)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_INSTRUMENTRepository.GetAllByProductCode(product.ToString()).FirstOrDefault(p => p.LABEL == instrument.LABEL);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), "Label is duplicated");
                if (product == ProductCode.BOND)
                {
                    LogBusiness logBusiness = new LogBusiness();
                    unitOfWork.DA_LOGGINGRepository.Add(logBusiness.CreateLogging(sessioninfo, instrument.ID, LogEvent.INSTRUMENT_AUDIT.ToString(), LookupFactorTables.MA_INSTRUMENT, "BOND", new { }));
                }
                unitOfWork.MA_INSTRUMENTRepository.Add(instrument);
                unitOfWork.Commit();
            }

            return instrument;
        }
Beispiel #3
0
        public static object Create(SessionInfo sessioninfo, MA_INSTRUMENT record)
        {
            try
            {
                InstrumentBusiness _instrumentBusiness = new InstrumentBusiness();
                ILookupValuesRepository _lookupvaluesRepository = RepositorySesssion.GetRepository();
                MA_PRODUCT product = _lookupvaluesRepository.ProductRepository.GetByID(record.PRODUCT_ID);

                ProductCode eProduct = (ProductCode)Enum.Parse(typeof(ProductCode), product.LABEL.Replace(" ", string.Empty));

                record.ID = Guid.NewGuid();
                record.ISACTIVE = record.ISACTIVE == null || !record.ISACTIVE ? false : true;
                record.LABEL = record.LABEL.ToUpper();

                if (eProduct != ProductCode.BOND)
                {
                    record.INS_MKT = null;
                    record.ISSUER = null;
                    record.LOT_SIZE = null;
                    record.COUPON = null;
                    record.MATURITY_DATE = null;
                    record.CAL_METHOD = null;
                    record.FLAG_FIXED = null;
                    record.COUPON_FREQ_TYPE_ID = null;
                }

                record.LOG.INSERTDATE = DateTime.Now;
                record.LOG.INSERTBYUSERID = sessioninfo.CurrentUserId;
                var addedRecord = _instrumentBusiness.Create(sessioninfo, record, eProduct);
                return new { Result = "OK", Record = addedRecord };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
 public static object Update(MA_INSTRUMENT record)
 {
     return InstrumentUIP.Update(SessionInfo, record);
 }
        public MA_INSTRUMENT Update(SessionInfo sessioninfo, MA_INSTRUMENT instrument, ProductCode product)
        {
            using (EFUnitOfWork unitOfWork = new EFUnitOfWork())
            {
                var checkDuplicate = unitOfWork.MA_INSTRUMENTRepository.GetAllByProductCode(product.ToString()).FirstOrDefault(p => p.LABEL == instrument.LABEL && p.ID != instrument.ID);
                if (checkDuplicate != null)
                    throw this.CreateException(new Exception(), "Label is duplicated");
                var foundData = unitOfWork.MA_INSTRUMENTRepository.GetAll().FirstOrDefault(p => p.ID == instrument.ID);
                if (foundData == null)
                    throw this.CreateException(new Exception(), "Data not found!");
                else
                {
                    if (product == ProductCode.BOND)
                    {
                        LogBusiness logBusiness = new LogBusiness();
                        var oldRecord = new
                        {
                                    ISACTIVE = foundData.ISACTIVE,
                                    CAL_METHOD = foundData.CAL_METHOD,
                                    COUPON = foundData.COUPON,
                                    COUPON_FREQ_TYPE = foundData.MA_FREQ_TYPE!= null ?foundData.MA_PRODUCT.LABEL:string.Empty,
                                    FLAG_FIXED = foundData.FLAG_FIXED,
                                    INS_MKT = foundData.INS_MKT,
                                    ISSUER = foundData.ISSUER,
                                    LABEL = foundData.LABEL,
                                    LOT_SIZE = foundData.LOT_SIZE,
                                    MATURITY_DATE = foundData.MATURITY_DATE,
                                    PRODUCT = foundData.MA_PRODUCT!= null ? foundData.MA_PRODUCT.LABEL:string.Empty,
                                    CURRENCY = foundData.MA_CURRENCY != null ? foundData.MA_CURRENCY.LABEL:string.Empty
                        };
                        var newRecord = new
                        {
                                    ISACTIVE = instrument.ISACTIVE,
                                    CAL_METHOD = instrument.CAL_METHOD,
                                    COUPON = instrument.COUPON,
                                    COUPON_FREQ_TYPE =unitOfWork.MA_FREQ_TYPERepository.All().FirstOrDefault(f=>f.ID==instrument.COUPON_FREQ_TYPE_ID).LABEL,
                                    FLAG_FIXED = instrument.FLAG_FIXED,
                                    INS_MKT = instrument.INS_MKT,
                                    ISSUER = instrument.ISSUER,
                                    LABEL = instrument.LABEL,
                                    LOT_SIZE = instrument.LOT_SIZE,
                                    MATURITY_DATE = instrument.MATURITY_DATE,
                                    PRODUCT = unitOfWork.MA_PRODUCTRepository.All().FirstOrDefault(p => p.ID == instrument.PRODUCT_ID).LABEL,
                                    CURRENCY = unitOfWork.MA_CURRENCYRepository.All().FirstOrDefault(c => c.ID == instrument.CURRENCY_ID1).LABEL,
                        };
                        var log = logBusiness.UpdateLogging(sessioninfo, foundData.ID, LogEvent.INSTRUMENT_AUDIT.ToString(), LookupFactorTables.MA_INSTRUMENT, oldRecord, newRecord);
                        if (log != null) unitOfWork.DA_LOGGINGRepository.Add(log);
                    }
                    foundData.ID = instrument.ID;
                    foundData.ISACTIVE = instrument.ISACTIVE;
                    foundData.LOG.MODIFYBYUSERID = sessioninfo.CurrentUserId;
                    foundData.LOG.MODIFYDATE = DateTime.Now;
                    foundData.CAL_METHOD = instrument.CAL_METHOD;
                    foundData.COUPON = instrument.COUPON;
                    foundData.COUPON_FREQ_TYPE_ID = instrument.COUPON_FREQ_TYPE_ID;
                    foundData.FLAG_FIXED = instrument.FLAG_FIXED;
                    foundData.INS_MKT = instrument.INS_MKT;
                    foundData.ISSUER = instrument.ISSUER;
                    foundData.LABEL = instrument.LABEL;
                    foundData.LOT_SIZE = instrument.LOT_SIZE;
                    foundData.MATURITY_DATE = instrument.MATURITY_DATE;
                    foundData.PRODUCT_ID = instrument.PRODUCT_ID;
                    foundData.CURRENCY_ID1 = instrument.CURRENCY_ID1;
                    foundData.CURRENCY_ID2 = instrument.CURRENCY_ID2;
                    unitOfWork.Commit();

                }
            }

            return instrument;
        }