コード例 #1
0
        public JsonResult PreferenceLayout(PreferenceRequest request)
        {
            var checkResult = CheckUsername(request.username);

            if (checkResult != null)
            {
                return(checkResult);
            }

            if (!CornerCaseCheckHelper.Check(request.preferenceLayout, 50, CornerCaseCheckHelper.Title))
            {
                return(JsonReturnHelper.ErrorReturn(111, "Invalid preferenceLayout"));
            }

            var user = _meshContext.Users.First(u => u.Email == request.username);

            try
            {
                user.LayoutPreference = request.preferenceLayout;
                _meshContext.Users.Update(user);
                _meshContext.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(JsonReturnHelper.ErrorReturn(1, "Unexpected error."));
            }

            return(JsonReturnHelper.SuccessReturn());
        }
コード例 #2
0
        public async Task <ActionResult <Preference> > MercadoPago([FromBody] dynamic preferencia)
        {
            MercadoPagoConfig.AccessToken = "TEST-5059945658019779-070913-a1924cb562898b6ed9191db0f41badf6-155784029";

            var request = new PreferenceRequest
            {
                Items = new List <PreferenceItemRequest>
                {
                    new PreferenceItemRequest
                    {
                        Title      = "Carrito",
                        Quantity   = 1,
                        CurrencyId = "ARS",
                        UnitPrice  = preferencia.total,
                    },
                },
                BackUrls = new PreferenceBackUrlsRequest
                {
                    Success = preferencia.frontURL,
                    Failure = preferencia.frontURL,
                    Pending = preferencia.frontURL
                },
                ExternalReference = Convert.ToString(preferencia.pedidoId),
                //no se puede configurar que haga notificaciones a localHost, debe ser una url publica
                // NotificationUrl = "https://localhost:44350/api/Pedidos/MercadoPagoNotificacion",
            };

            // Crea la preferencia usando el client
            var        client     = new PreferenceClient();
            Preference preference = await client.CreateAsync(request);

            return(preference);
        }
コード例 #3
0
        public void Create_Success()
        {
            PreferenceRequest request = BuildRequest();

            Preference preference = preferenceClient.Create(request);

            Assert.NotNull(preference);
            Assert.NotNull(preference.Id);
            Assert.Equal(request.ExternalReference, preference.ExternalReference);
        }
コード例 #4
0
        public async Task CreateAsync_Success()
        {
            PreferenceRequest request = BuildRequest();

            Preference preference = await preferenceClient.CreateAsync(request);

            Assert.NotNull(preference);
            Assert.NotNull(preference.Id);
            Assert.Equal(request.ExternalReference, preference.ExternalReference);
        }
コード例 #5
0
        public void Get_Success()
        {
            // Creates a preference
            PreferenceRequest createRequest     = BuildRequest();
            Preference        createdPreference = preferenceClient.Create(createRequest);

            Preference preference = preferenceClient.Get(
                createdPreference.Id);

            Assert.NotNull(preference);
            Assert.Equal(createdPreference.Id, preference.Id);
        }
コード例 #6
0
        public async Task GetAsync_Success()
        {
            // Creates a preference
            PreferenceRequest createRequest     = BuildRequest();
            Preference        createdPreference = await preferenceClient.CreateAsync(createRequest);

            Preference preference = await preferenceClient.GetAsync(
                createdPreference.Id);

            Assert.NotNull(preference);
            Assert.Equal(createdPreference.Id, preference.Id);
        }
コード例 #7
0
        public async Task <object> AddEditPreference(PreferenceRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(JsonResults.Error(400, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage.ToString()));
            }

            try
            {
                var checkPreference = await _preferenceService.CheckPreference(request);

                if (!checkPreference)
                {
                    var model = new Preference
                    {
                        UserId    = request.UserId,
                        ServiceId = request.ServiceId,
                        Checked   = true
                    };

                    await _preferenceService.AddPreference(model);

                    return(JsonResults.Success(GetPreferenceModel(model)));
                }

                var preference = await _preferenceService.GetPreference(request.Id);

                preference.ServiceId = request.ServiceId;
                preference.Checked   = true;

                await _preferenceService.UpdatePreference(preference);

                return(JsonResults.Success(GetPreferenceModel(preference)));
            }
            catch (Exception ex)
            {
                return(JsonResults.Error(400, ex.Message));
            }
        }
コード例 #8
0
        private Task <Preference> CreatePreferenceAsync()
        {
            var request = new PreferenceRequest
            {
                Items = new List <PreferenceItemRequest>
                {
                    new PreferenceItemRequest
                    {
                        Description = "Description",
                        Id          = "123",
                        PictureUrl  = "http://product.image.png",
                        Quantity    = 1,
                        Title       = "Title",
                        UnitPrice   = 100,
                    },
                },
            };

            var client = new PreferenceClient();

            return(client.CreateAsync(request));
        }
コード例 #9
0
        public async Task UpdateAsync_Success()
        {
            // Creates a preference
            PreferenceRequest createRequest     = BuildRequest();
            Preference        createdPreference = await preferenceClient.CreateAsync(createRequest);

            var updateRequest = new PreferenceRequest
            {
                Items = new List <PreferenceItemRequest>
                {
                    new PreferenceItemRequest
                    {
                        Description = "Item 1",
                        Id          = "123",
                        PictureUrl  = "http://product1.image.png",
                        Quantity    = 1,
                        Title       = "Item 1",
                        UnitPrice   = 100,
                    },
                    new PreferenceItemRequest
                    {
                        Description = "Item 2",
                        Id          = "456",
                        PictureUrl  = "http://product2.image.png",
                        Quantity    = 2,
                        Title       = "Item 2",
                        UnitPrice   = 200,
                    },
                },
            };
            Preference preference = await preferenceClient.UpdateAsync(
                createdPreference.Id, updateRequest);

            Assert.NotNull(preference);
            Assert.NotNull(preference.Items);
            Assert.True(preference.Items.Count == 2);
        }
コード例 #10
0
        public async Task <bool> CheckPreference(PreferenceRequest request)
        {
            var preferences = await db.Preferences.Where(p => p.UserId == request.UserId && p.ServiceId == request.ServiceId).FirstOrDefaultAsync();

            return(preferences != null);
        }