Ejemplo n.º 1
0
        public List <SaveResultData> InsertNewLeads(string ticketId, List <ProductData> productList, string username, string staffNameTH, string channelId, string channelDesc)
        {
            List <SaveResultData> resultList = new List <SaveResultData>();
            DateTime createdDate             = DateTime.Now;

            string               jobOnHand = "";
            KKSlmMsStaffModel    staff     = new KKSlmMsStaffModel();
            StaffAmountJobOnHand tmp       = staff.GetAmountJobOnHand(username);

            if (tmp != null)
            {
                jobOnHand = " (" + (tmp.AmountOwner + tmp.AmountDelegate).ToString() + " งาน)";
            }

            foreach (ProductData product in productList)
            {
                try
                {
                    SLM_DBEntities slmdb        = new SLM_DBEntities();
                    StoreProcedure store        = new StoreProcedure();
                    string         new_ticketId = store.GenerateTicketId();

                    KKSlmTrLeadModel lead = new KKSlmTrLeadModel(slmdb);
                    lead.InsertData(ticketId, new_ticketId, product, username, createdDate, channelId);

                    KKSlmTrCusInfoModel customerInfo = new KKSlmTrCusInfoModel(slmdb);
                    customerInfo.InsertData(ticketId, new_ticketId, username, createdDate);

                    KKSlmTrProductInfoModel productInfo = new KKSlmTrProductInfoModel(slmdb);
                    productInfo.InsertData(ticketId, new_ticketId, username, createdDate);

                    KKSlmTrChannelInfoModel channelInfo = new KKSlmTrChannelInfoModel(slmdb);
                    channelInfo.InsertData(ticketId, new_ticketId, username, createdDate, channelId);

                    KKSLMTrCampaignFinalModel camFinal = new KKSLMTrCampaignFinalModel(slmdb);
                    camFinal.InsertData(new_ticketId, product, username, createdDate);

                    KKSlmTrHistoryModel.InsertHistory(slmdb, new_ticketId, SLMConstant.HistoryTypeCode.CreateLead, "", "", username, createdDate);

                    slmdb.SaveChanges();

                    SaveResultData data = new SaveResultData()
                    {
                        TicketId     = new_ticketId,
                        CampaignName = product.CampaignName,
                        ChannelDesc  = channelDesc,
                        Ownername    = staffNameTH + jobOnHand
                    };
                    resultList.Add(data);
                }
                catch (Exception ex)
                {
                    _errList.Add(product.CampaignId, ex.Message);
                }
            }

            return(resultList);
        }