Exemple #1
0
        public static Main CreateRequest(DataAccess.Entities.Request request)
        {
            Main main = new Main
            {
                UserId                 = request.User.UserId,
                Btn                    = request.Phone,
                AccountFirstName       = request.FirstName,
                AccountLastName        = request.LastName,
                AuthorizationFirstName = request.FirstName,
                AuthorizationLastName  = request.LastName,
                NumberOfAccounts       = request.OrderDetails.Count.ToString(),
                Verified               = "9",
                WebDateTime            = DateTime.Now,
                Concern                = "No TPV Call",
                OrderDetails           = new List <OrderDetail>(),
                IpLocations            = new List <IpLocation>()
            };

            main.IpLocations.Add(new IpLocation
            {
                Ip       = request.IpLocation?.Ip,
                City     = request.IpLocation?.City,
                Country  = request.IpLocation?.Country,
                HostName = request.IpLocation?.HostName,
                Loc      = request.IpLocation?.Loc,
                Org      = request.IpLocation?.Org,
                Postal   = request.IpLocation?.Postal,
                Region   = request.IpLocation?.Region
            });

            foreach (DataAccess.Entities.Request.RequestOrderDetail detail in request.OrderDetails)
            {
                main.Relation = detail.Relationship;

                OrderDetail o = new OrderDetail
                {
                    AccountNumber          = detail.AccountNumber,
                    AccountType            = detail.Program.AccountNumberType?.AccountNumberTypeName ?? "Unknown",
                    UtilityType            = detail.UtilityType,
                    BillingAddress         = $"{detail.BillingAddress} {detail.BillingAddress2}",
                    BillingCity            = detail.BillingCity,
                    BillingState           = detail.BillingState,
                    BillingZip             = detail.BillingZip,
                    BillingFirstName       = detail.BillingFirstName,
                    BillingLastName        = detail.BillingLastName,
                    ServiceAddress         = $"{detail.Address} {detail.Address2}",
                    ServiceCity            = detail.City,
                    ServiceState           = detail.State,
                    ServiceZip             = detail.Zip,
                    ServiceBuildingType    = detail.BuildingType,
                    MeterNumber            = detail.MeterNumber,
                    ServiceReferenceNumber = detail.ServiceReference,
                    ProgramId = detail.Program.ProgramId
                };

                main.OrderDetails.Add(o);
            }

            using (CustomClearviewEntities ctx = new CustomClearviewEntities())
            {
                MainRepository repo = new MainRepository(ctx);
                repo.Create(main);
                ctx.SaveChanges();
            }

            return(main);
        }