public void Add(TrafficSourcesEcommerce botDomain)
 {
     _botDomainRepository.Add(botDomain);
 }
 public void Update(TrafficSourcesEcommerce botDomain)
 {
     _botDomainRepository.Update(botDomain);
 }
Exemple #3
0
        public IActionResult Post([FromBody] Welcome welcome)
        {
            var           reports    = welcome.FormattedJson;
            var           project    = welcome.Project;
            IActionResult _result    = new ObjectResult(false);
            GenericResult _addResult = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }



                //ADD
                var version = _trafficSourcesEcommerceService.GetVersionFinal(project["PROJECT_ID"]);

                _trafficSourcesEcommerceService.RemoveVersionOld(project["PROJECT_ID"]);


                var rows = reports.Reports[0].Data.Rows;
                if (rows == null)
                {
                    _addResult = new GenericResult()
                    {
                        Succeeded = false,
                        Message   = "Không có dữ liệu trong 30 ngày gần nhất"
                    };
                    _result = new ObjectResult(_addResult);
                    return(_result);
                }
                for (int i = 0; i < rows.Length; i++)
                {
                    var source = rows[i].Dimensions[0];
                    var values = rows[i].Metrics[0].Values;

                    //    decimal moeny = Decimal.Parse(values[0], System.Globalization.NumberStyles.Any);
                    //  var moeny= Double.Parse(values[0], System.Globalization.NumberStyles.Float);

                    //string[] moeny = values[0].ToString().Split('E');
                    //var x = Double.Parse(moeny[0])*(10^moeny)
                    TrafficSourcesEcommerce newTrafficSourcesEcommerce = new TrafficSourcesEcommerce
                    {
                        TRAFFIC_SOURCE_ECOMMERCE_ID = 0,
                        SOURCE = source,
                        //   MEDIUM = values[0],
                        SESSIONS           = values[0],
                        SESSIONDURATION    = values[1],
                        PAGEVIEWS          = values[2],
                        EXITS              = values[3],
                        TRANSACTIONS       = values[4],
                        TRANSACTIONREVENUE = values[5],


                        CREATE_DT     = DateTime.Now,
                        RECORD_STATUS = "1",
                        VERSION_INT   = version + 1,
                        VERSION       = (version + 1).ToString(),

                        PROJECT_ID = project["PROJECT_ID"],
                        DOMAIN     = project["DOMAIN"]
                    };
                    _trafficSourcesEcommerceService.Add(newTrafficSourcesEcommerce);
                    _trafficSourcesEcommerceService.Save();
                }

                //TrafficSourcesEcommerce _newTrafficSourcesEcommerce = PropertyCopy.Copy<TrafficSourcesEcommerce, DomainViewModel>(TrafficSourcesEcommerce);


                //_newTrafficSourcesEcommerce.CREATE_DT = DateTime.Now;
                //_newTrafficSourcesEcommerce.PROJECT_ID = 1;



                _addResult = new GenericResult()
                {
                    Succeeded = true,
                    Message   = "Add success."
                };
            }
            catch (Exception ex)
            {
                _addResult = new GenericResult()
                {
                    Succeeded = false,
                    Message   = ex.Message
                };

                _loggingRepository.Add(new Error()
                {
                    Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now
                });
                _loggingRepository.Commit();
            }

            _result = new ObjectResult(_addResult);
            return(_result);
        }