Пример #1
0
        public async Task<Plan> CreatePlan(CreatePlanModel model)
        {
            using (var connection = _connectionHelper.GetConnection())
            {
                var projectId = await connection
                    .ExecuteScalarAsync<int>("SELECT [ID] FROM [Project] WHERE [Guid] = @Guid",
                        new {Guid = model.ProjectGuid}).ConfigureAwait(false);

                if (projectId == default(int))
                    throw new EntityNotFoundException($"Unable to find the project with the guid: {model.ProjectGuid}");

                var id = await connection.ExecuteScalarAsync<int>(@"
                    INSERT INTO [Plan] ([Name], [Description], [ProjectId], [ProjectGuid], [Enabled])
                    VALUES (@Name, @Description, @ProjectId, @ProjectGuid, @Enabled)
                    SELECT SCOPE_IDENTITY()",
                    new
                    {
                        ProjectId = projectId,
                        model.Name,
                        model.Description,
                        model.ProjectGuid,
                        model.Enabled
                    }
                ).ConfigureAwait(false);

                return await connection
                    .QuerySingleOrDefaultAsync<Plan>(@"SELECT * FROM [Plan] WHERE [Id] = @Id", new {Id = id})
                    .ConfigureAwait(false);
            }
        }
Пример #2
0
        public IActionResult AddPlanToVehicles(CreatePlanModel model)
        {
            if (!LogedIn())
            {
                return(RedirectToRoute("Home"));
            }
            Plan plan = new Plan();

            plan.Name    = model.Title;
            plan.Company = _context.Companies.Find(CompanyId);
            _context.Add(plan);
            _context.SaveChanges();
            plan.Activities = new List <Activity>();
            for (int i = 0; i < model.SelectedServices.Length; i++)
            {
                if (model.SelectedServices[i] == 0 || model.ActivityPeriod[i] == 0)
                {
                    continue;
                }
                Activity A = new Activity();
                A.Service = _context.Service.Find(model.SelectedServices[i]);
                A.Period  = model.ActivityPeriod[i];

                plan.Activities.Add(A);
                _context.Add(A);
            }
            _context.SaveChanges();
            HttpContext.Session.SetInt32("PlanId", (int)plan.Id);
            ViewData["type"] = HttpContext.Session.GetString("OrderType");

            ViewData["Vehicles"] = _context.Vehicles.Where(v => v.Company.Id == CompanyId).ToArray <Vehicle>();
            return(View());
        }
Пример #3
0
        public async Task <PlanModel> CreatePlan(CreatePlanModel model)
        {
            var entity = await _planData.CreatePlan(model).ConfigureAwait(false);

            var mappedModel = _mapper.Map <PlanModel>(entity);

            return(mappedModel);
        }
Пример #4
0
        public ActionResult CreatePlan()
        {
            var model = new CreatePlanModel
            {
                TimeZone     = _converter.GetCurrenTimeZone(),
                BaseCurrency = _storage.GetBaseCurrency()
            };

            return(View(model));
        }
Пример #5
0
        // GET: Plans/Create
        public IActionResult Create()
        {
            if (!LogedIn())
            {
                return(RedirectToRoute("Home"));
            }
            CreatePlanModel model = new CreatePlanModel();

            model.FillServices(_context, CompanyId);
            return(View(model));
        }
        public JsonResult CreatePlan([DataSourceRequest]  DataSourceRequest request, CreatePlanModel Plan)
        {
            if (Plan == null || !ModelState.IsValid)
            {
                return Json(new[] { Plan }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
            }

            var createdPlan = this.plansServices.CreatePlan(Plan);

            return Json(new[] { createdPlan }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
        }
Пример #7
0
        /*
         * METODOS RELACIONADOS CON PLANS
         */
        public CreatePlanModel PlanCreate(string id_plan, string name, string description, decimal amount, string currency, string interval, int interval_count, int trial_days)
        {
            ENDPOINT  = Constants.url_create_plan;
            PARAMETER = body.getBodyCreatePlan(id_plan, name, description, amount, currency, interval, interval_count, trial_days);
            string content = _request.Execute(
                ENDPOINT,
                "POST",
                _auxiliars.ConvertToBase64(_PUBLIC_KEY),
                PARAMETER);
            CreatePlanModel plan = JsonConvert.DeserializeObject <CreatePlanModel>(content);

            return(plan);
        }
Пример #8
0
        public async Task <IHttpActionResult> CreatePlan([FromBody] CreatePlanModel model)
        {
            try
            {
                var result = await _planOperations.CreatePlan(model).ConfigureAwait(false);

                return(Ok(result));
            }
            catch (EntityNotFoundException)
            {
                return(BadRequest());
            }
        }
        public PlanViewModel CreatePlan(CreatePlanModel plan)
        {
            var newPlan = new Plan()
            {
                Name = plan.Name
            };

            this.Data.Plans.Add(newPlan);
            this.Data.SaveChanges();

            var createdPlan = this.GetPlanById(newPlan.Id);
            return createdPlan;
        }
Пример #10
0
        public IActionResult CreatePlan()
        {
            CreatePlanModel plan = epayco.PlanCreate(
                "alejo-epayco-sdk-prueba2565",
                "prueba 4",
                "prueba sdk alejo",
                5000,
                "cop",
                "month",
                1,
                0);


            return(Ok(plan));
        }
Пример #11
0
        public IHttpActionResult AddPlan(CreatePlanModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                _planOperations.CreatePlan(model, _currentUserProvider.CurrentUserId);
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));

                throw;
            }
        }
Пример #12
0
        public int CreatePlan(CreatePlanModel model, int currUserId)
        {
            var user = _unitOfWork.Repository <UserEntity>().GetById(currUserId);

            var entityToInsert = new PlanEntity
            {
                Blocks      = new List <BlockExersiceEntity>(),
                Name        = model.Name,
                Owner       = user,
                Description = model.Description,
                Followers   = new List <UserEntity>(),
                Type        = model.Type
            };

            _unitOfWork.Repository <PlanEntity>().Insert(entityToInsert);
            _unitOfWork.SaveChanges();

            return(entityToInsert.Id);
        }
Пример #13
0
        public ActionResult CreatePlan(CreatePlanModel model)
        {
            DateTime?st = null, et = null;
            double?  am = null;
            DateTime lst, let;

            if (DateTime.TryParseExact(model.StartDate, "dd.MM.yyyy", null, DateTimeStyles.None, out lst))
            {
                st = _converter.GetUtcDateTime(lst);
            }
            if (DateTime.TryParseExact(model.EndDate, "dd.MM.yyyy", null, DateTimeStyles.None, out let))
            {
                et = _converter.GetUtcDateTime(new DateTime(let.Year, let.Month, let.Day, 23, 59, 59));
            }
            double lam;

            if (double.TryParse(model.Amount, out lam))
            {
                am = lam;
            }
            if (st.HasValue && et.HasValue && am.HasValue)
            {
                var plan = _storage.CreatePlan(new Plan()
                {
                    Amount    = am.Value,
                    StartDate = st.Value,
                    EndDate   = et.Value
                });
                ViewBag.Success = $"Создан план № {plan.Id}. C {_converter.GetActualDateTime(plan.StartDate):M} по {_converter.GetActualDateTime(plan.EndDate):M} ";
                ModelState.Clear();
                return(View(new CreatePlanModel
                {
                    TimeZone = _converter.GetCurrenTimeZone(),
                    BaseCurrency = _storage.GetBaseCurrency()
                }));
            }
            ViewBag.Error      = "Can't parse values";
            model.TimeZone     = _converter.GetCurrenTimeZone();
            model.BaseCurrency = _storage.GetBaseCurrency();
            return(View(model));
        }
Пример #14
0
        public async Task CreatePlan_ShouldReturnTheCreatedPlan()
        {
            var planOperations = new Mock <IPlanOperations>();

            var model    = new CreatePlanModel();
            var expected = new PlanModel();

            planOperations.Setup(o => o.CreatePlan(model)).ReturnsAsync(expected);

            var controller = new PlanController(planOperations.Object);

            var result =
                await controller.CreatePlan(model).ConfigureAwait(false) as OkNegotiatedContentResult <PlanModel>;

            if (result == null)
            {
                Assert.Fail();
            }

            Assert.AreEqual(expected, result.Content);
        }
Пример #15
0
        public async Task <CreatePlanModel> CreatePlan(CreateSubscriptionPlanCommand command)
        {
            Frequency frequency = new Frequency()
            {
                interval_unit  = "MONTH",
                interval_count = 1
            };

            FixedPrice fixedPrice = new FixedPrice()
            {
                value         = "10",
                currency_code = "USD"
            };

            PricingScheme pricingScheme = new PricingScheme()
            {
                fixed_price = fixedPrice
            };

            List <BillingCycle> billing_cycles = new List <BillingCycle>()
            {
                new BillingCycle()
                {
                    frequency    = frequency,
                    tenure_type  = "TRIAL",
                    sequence     = 1,
                    total_cycles = 1,
                    //pricing_scheme = pricingScheme
                },

                new BillingCycle()
                {
                    frequency   = frequency,
                    tenure_type = "REGULAR",
                    sequence    = 2,
                    //total_cycles = 12,
                    total_cycles   = command.BillingCycles,
                    pricing_scheme = pricingScheme
                }
            };

            Taxes taxes = new Taxes()
            {
                percentage = "10",
                inclusive  = false
            };

            SetupFee setupFee = new SetupFee()
            {
                //value = "10",
                value         = command.SubscriptionSetupFee,
                currency_code = "USD"
            };

            PaymentPreferences paymentPreferences = new PaymentPreferences()
            {
                auto_bill_outstanding     = true,
                setup_fee                 = setupFee,
                setup_fee_failure_action  = "CONTINUE",
                payment_failure_threshold = 3
            };

            CreatePlanModel createPlanModel = new CreatePlanModel()
            {
                ProductId = "product_social_marketing",
                //ProductId = command.ProductId,
                //Name = "Basic Plan",
                Name = command.PlanName,
                //Description = "Basic plan",
                Description        = command.PlanDescription,
                BillingCycles      = billing_cycles,
                PaymentPreferences = paymentPreferences,
                Taxes = taxes
            };

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", BearerToken);

            var result = await _httpClient.PostAsJsonAsync <CreatePlanModel>("https://api-m.sandbox.paypal.com/v1/billing/plans", createPlanModel);

            //Working
            //var result = await _httpClient.PostAsync("https://api-m.sandbox.paypal.com/v1/billing/plans", new StringContent(json, Encoding.UTF8, "application/json"));
            //var json = System.Text.Json.JsonSerializer.Serialize(createPlanModel);



            //var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, $"https://api-m.sandbox.paypal.com/v1/billing/plans")
            //{
            //  Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(createPlanModel), System.Text.Encoding.UTF8, "application/json")
            //});

            //var result = await _httpClient.PostAsync($"https://api-m.sandbox.paypal.com/v1/billing/plans?{json}", new System.Net.Http.StringContent(json/*, Encoding.UTF8, "application/json"*/));
            //await _httpClient.PostAsync(_configuration["SisSendBulkSmsURL"], new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json"));
            //await _httpClient.PostAsync(, new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json"));
            //var responsee = await _httpClient.PostAsync($"https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=product_social_marketing&name=BasicPlan&description=Basicplan&billing_cycles[0][frequency][interval_unit]=MONTH&billing_cycles[0][frequency][interval_count]=1&billing_cycles[0][tenure_type]=TRIAL&billing_cycles[0][sequence]=1&billing_cycles[0][total_cycles]=1&billing_cycles[1][frequency][interval_unit]=MONTH&billing_cycles[1][frequency][interval_count]=1&billing_cycles[1][tenure_type]=REGULAR&billing_cycles[1][sequence]=2&billing_cycles[1][total_cycles]=12&billing_cycles[1][pricing_scheme][fixed_price][value]=10&billing_cycles[1][pricing_scheme][fixed_price][currency_code]=USD&payment_preferences[auto_bill_outstanding]=true&payment_preferences[setup_fee][value]=10&payment_preferences[setup_fee][currency_code]=USD&payment_preferences[setup_fee_failure_action]=CONTINUE&payment_preferences[payment_failure_threshold]=3&taxes[percentage]=10&taxes[inclusive]=false",null);

            if (result.IsSuccessStatusCode)
            {
                string content = await result.Content.ReadAsStringAsync();

                //All properties are getting null except name and description
                createPlanModel = Newtonsoft.Json.JsonConvert.DeserializeObject <CreatePlanModel>(content);
                //objects are getting null, properties are filled
                createPlanModel = await result.Content.ReadFromJsonAsync <CreatePlanModel>();
            }

            else
            {
                string content = await result.Content.ReadAsStringAsync();
            }

            return(createPlanModel);
        }