示例#1
0
        public ActionResult detail(string accountid, string callid)
        {
            var client = new RestClient("https://api.calltrackingmetrics.com");

            var req = new RestRequest("api/v1/accounts/" + accountid + "/calls/" + callid, Method.GET);

            req.AddHeader("Authorization", api);

            IRestResponse response = client.Execute(req);
            var           content  = response.Content;
            CallDetail    m        = JsonConvert.DeserializeObject <CallDetail>(response.Content);


            return(View(m));
        }
    public void TestCode()
    {
        var items = new List <CallKeyValue>
        {
            new CallKeyValue {
                CallKey = CallKey.CallDate, Value1 = "11.04.2017"
            },
            new CallKeyValue {
                CallKey = CallKey.CallTime, Value1 = "15:43"
            },
            new CallKeyValue {
                CallKey = CallKey.FromPhoneNumber, Value1 = "5311234567"
            },
            new CallKeyValue {
                CallKey = CallKey.ToPhoneNumber, Value1 = "5311234587 "
            },
            new CallKeyValue {
                CallKey = CallKey.Duration, Value1 = "13*min"
            },
            new CallKeyValue {
                CallKey = CallKey.FromOperatorCode, Value1 = "TR", Value2 = "001"
            },
            new CallKeyValue {
                CallKey = CallKey.ToOperatorCode, Value1 = "TR", Value2 = "002"
            },
        };
        var st = new Stopwatch();

        //Test 1: ElapsedMilliseconds: 50, ElapsedTicks: 122023
        st.Start();
        IDictionary <string, dynamic> expando = new ExpandoObject();

        foreach (var item in items)
        {
            expando.Add(item.CallKey.ToString(), null);
            expando[item.CallKey.ToString()] = new { Value1 = item.Value1, Value2 = item.Value2 };
        }
        var cd = new CallDetail {
            CallDate            = DateTime.Parse(expando[CallKey.CallDate.ToString()].Value1 + " " + expando[CallKey.CallTime.ToString()].Value1),
            FromPhoneNumber     = expando[CallKey.FromPhoneNumber.ToString()].Value1,
            ToPhoneNumber       = expando[CallKey.ToPhoneNumber.ToString()].Value1,
            Duration            = Convert.ToInt32(expando[CallKey.Duration.ToString()].Value1.ToString().Split('*')[0]),
            DurationUnit        = GetEnumKeyOfUnit(expando[CallKey.Duration.ToString()].Value1.ToString().Split('*')[1]),
            FromOperatorCountry = expando[CallKey.FromOperatorCode.ToString()].Value1,
            FromOperatorId      = expando[CallKey.FromOperatorCode.ToString()].Value2,
            ToOperatorCountry   = expando[CallKey.ToOperatorCode.ToString()].Value1,
            ToOperatorId        = expando[CallKey.ToOperatorCode.ToString()].Value2
        };

        st.Stop();
        Console.WriteLine(st.ElapsedMilliseconds);
        Console.WriteLine(st.ElapsedTicks);
        st.Reset();
        //Test 2: ElapsedMilliseconds: 0, ElapsedTicks: 328
        st.Start();
        var cd3 = items.Select(s => {
            IDictionary <string, dynamic> expando2 = new ExpandoObject();
            expando2.Add(s.CallKey.ToString(), null);
            expando2[s.CallKey.ToString()] = new { Value1 = s.Value1, Value2 = s.Value2 };
            var item = new CallDetail {
                CallDate            = DateTime.Parse(expando2[CallKey.CallDate.ToString()].Value1 + " " + expando2[CallKey.CallTime.ToString()].Value1),
                FromPhoneNumber     = expando2[CallKey.FromPhoneNumber.ToString()].Value1,
                ToPhoneNumber       = expando2[CallKey.ToPhoneNumber.ToString()].Value1,
                Duration            = Convert.ToInt32(expando2[CallKey.Duration.ToString()].Value1.ToString().Split('*')[0]),
                DurationUnit        = GetEnumKeyOfUnit(expando2[CallKey.Duration.ToString()].Value1.ToString().Split('*')[1]),
                FromOperatorCountry = expando2[CallKey.FromOperatorCode.ToString()].Value1,
                FromOperatorId      = expando2[CallKey.FromOperatorCode.ToString()].Value2,
                ToOperatorCountry   = expando2[CallKey.ToOperatorCode.ToString()].Value1,
                ToOperatorId        = expando2[CallKey.ToOperatorCode.ToString()].Value2
            };
            return(item);
        });

        st.Stop();
        Console.WriteLine(st.ElapsedMilliseconds);
        Console.WriteLine(st.ElapsedTicks);
        st.Reset();
        //Test 3: ElapsedMilliseconds: 0, ElapsedTicks: 1390
        st.Start();
        var cd2 = new CallDetail {
            CallDate            = DateTime.Parse(items.FirstOrDefault(f => f.CallKey == CallKey.CallDate)?.Value1 + " " + items.FirstOrDefault(f => f.CallKey == CallKey.CallTime)?.Value1),
            FromPhoneNumber     = items.FirstOrDefault(f => f.CallKey == CallKey.FromPhoneNumber)?.Value1,
            ToPhoneNumber       = items.FirstOrDefault(f => f.CallKey == CallKey.ToPhoneNumber)?.Value1,
            Duration            = Convert.ToInt32(items.FirstOrDefault(f => f.CallKey == CallKey.Duration)?.Value1.Split('*')[0]),
            DurationUnit        = GetEnumKeyOfUnit(items.FirstOrDefault(f => f.CallKey == CallKey.Duration)?.Value1.Split('*')[1]),
            FromOperatorCountry = items.FirstOrDefault(f => f.CallKey == CallKey.FromOperatorCode)?.Value1,
            FromOperatorId      = items.FirstOrDefault(f => f.CallKey == CallKey.FromOperatorCode)?.Value2,
            ToOperatorCountry   = items.FirstOrDefault(f => f.CallKey == CallKey.ToOperatorCode)?.Value1,
            ToOperatorId        = items.FirstOrDefault(f => f.CallKey == CallKey.ToOperatorCode)?.Value2
        };

        st.Stop();
        Console.WriteLine(st.ElapsedMilliseconds);
        Console.WriteLine(st.ElapsedTicks);
    }
示例#3
0
        public ActionResult Create(CallViewModel callViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Call     call     = new Call();
                    Customer customer = new Customer();



                    Representative rep = new Representative
                    {
                        RepresentativeID = new Guid(),
                        FamilyName       = callViewModel.RepFamilyName,
                        FirstName        = callViewModel.RepFirstName,
                        MidName          = callViewModel.RepMidName,
                        Position         = callViewModel.RepPosition,
                        PhoneNumber      = callViewModel.RepPhoneNumber
                    };

                    //TempData["msg"] = "<script>alert(@model.JudicialStatus);</script>";
                    //ViewBag.Jstat = callViewModel.JudicialStatus;
                    callexp = (from e in db.Experts
                               where (e.ExpertID == callViewModel.ExpID)
                               select(e.Position.PositionDescr + e.FamilyName + e.FirstName + e.MidName)).FirstOrDefault();

                    customer.CustomerID = new Guid();
                    call.CustomerID     = customer.CustomerID;
                    customer.Name       = callViewModel.CustomerName;
                    //customer.RepresentativeID = rep.RepresentativeID;


                    var js = Int32.Parse(callViewModel.JudicialStatus);


                    customer.JudicialStatusID = (from j in db.JudicialStatuses
                                                 where (j.JudicialStatus1 == js)
                                                 select(j.JudicialStatusID)).FirstOrDefault();

                    customer.Address       = callViewModel.CustomerAddress;
                    customer.TaxID         = callViewModel.TaxID;
                    customer.OKPO          = callViewModel.OKPO;
                    customer.Account       = callViewModel.CustomerBankAccount;
                    customer.BankBranch    = callViewModel.BankBranch;
                    customer.BranchAddress = callViewModel.BranchAddress;
                    customer.BankCode      = callViewModel.BankCode;
                    customer.BIC           = callViewModel.BIC;
                    customer.PhoneNumber   = callViewModel.CustomerPhoneNumber;
                    customer.MPhoneNumber  = callViewModel.MPhoneNumber;

                    customer.RepresentativeID = rep.RepresentativeID;

                    callViewModel.CallID = Guid.NewGuid();
                    //callViewModel.ItemID = Guid.NewGuid();
                    call.CallID        = callViewModel.CallID;
                    call.CallName      = callViewModel.CallName;
                    call.CallDate      = callViewModel.CallDate;
                    call.SampleActDate = callViewModel.SampleActDate;
                    call.DocNumber     = callViewModel.Number;
                    call.ContractDate  = DateTime.Today; //DateTime.Today.ToString("d MMMM yyyy г.", CultureInfo.GetCultureInfo("ru-ru"));
                    call.DocType       = callViewModel.DocType;
                    call.AffidavitDate = callViewModel.AffidavitDate;
                    call.AffidavitNum  = callViewModel.AffidavitNum;



                    List <decimal> testCosts = new List <decimal>();

                    //item.ItemID = callViewModel.ItemID;
                    //item.ItemName = callViewModel.ItemName;
                    //item.ItemProducer = callViewModel.ItemProducer;


                    foreach (var i in callViewModel.ItemsList)
                    {
                        CallDetail callDetail = new CallDetail();
                        CalcDetail cd         = new CalcDetail();
                        Item       item       = new Item();
                        //Debugger.Break();
                        var itID = (from prog in db.Programs
                                    where (prog.ProgramNameShort.Equals(i.ProgramNameShort))
                                    select(prog.ItemTypeID)).FirstOrDefault();

                        callDetail.CallID    = call.CallID;
                        callDetail.ProgramID = (from prog in db.Programs
                                                where (prog.ProgramNameShort.Equals(i.ProgramNameShort))
                                                select prog.ProgramID).FirstOrDefault();

                        i.ItemID           = Guid.NewGuid();
                        item.ItemID        = callDetail.ItemID = i.ItemID;
                        item.ItemName      = i.ItemName;
                        item.ItemProducer  = i.ItemProducer;
                        callDetail.ItemQty = i.ItemQty;
                        item.Additional    = i.Additional;
                        cd.CalcID          = item.CalcDetailsID = new Guid();


                        //////////////////////////////////////// IMAGE PATH //////////////////////////////////////////


                        item.ImagePath = "";

                        item.ItemSubtypeID = (from ist in db.ItemSubtypes
                                              where (ist.ItemSubtypeID == i.ItemSubtype)
                                              select(ist.ItemSubtypeID)).FirstOrDefault();
                        //Debugger.Break();
                        var progDuration = (from prog in db.Programs
                                            where (prog.ProgramNameShort.Equals(i.ProgramNameShort))
                                            select(prog.DurationPerUnit)).FirstOrDefault();

                        decimal itemsDuration;

                        if (!progDuration.HasValue)
                        {
                            progDuration = 1000;
                        }

                        itemsDuration = (decimal)(progDuration * i.ItemQty);

                        //var lastDate = db.Calculations.Select(a => new { a.CurentDate }).ToList().Max(p => p);
                        var calcdata = db.Calculations.Select(a => new { a.CurentDate, a.ConsumablesCost, a.HourFee, a.EquipmentMaintanance }).OrderByDescending(t => t.CurentDate).First();

                        callDetail.ItemTestCost = calcdata.HourFee * (decimal)itemsDuration;

                        //Ввод каждой себестоимости проведения исследования вида объекта

                        testCosts.Add(callDetail.ItemTestCost);
                        cd.CalcDate = Convert.ToDateTime(i.calcDate, new CultureInfo("RU-ru"));
                        cd.CalcNum  = i.calcNum;

                        db.Items.Add(item);
                        db.CalcDetails.Add(cd);
                        db.CallDetails.Add(callDetail);
                    }

                    Debugger.Break();


                    db.Representatives.Add(rep);
                    db.Customers.Add(customer);

                    db.Calls.Add(call);
                    //db.CallViewModels.Add(callViewModel);
                    db.SaveChanges();
                }

                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                            ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                }

                catch (NullReferenceException ne)
                {
                    Debug.WriteLine(ne);
                }


                return(RedirectToAction("Index"));
            }
            return(View());
        }