Example #1
0
        public async Task <ActionResult <AdvertisingBase> > Create([FromBody] AdvertisingBase upsertRequest)
        {
            upsertRequest.AdvertisingId = 0;
            var response = await _adService.AddAdvertisingAsync(upsertRequest);

            return(CreatedAtRoute("GetAdvertising", new { id = response.AdvertisingId, token = response.Token }, response));
        }
Example #2
0
        public async Task <ActionResult> Paid(string notification_type, string operation_id, string label, string datetime
                                              , decimal amount, decimal withdraw_amount, string sender, string sha1_hash, string currency, bool codepro)
        {
            AppSettingsReader reader = new AppSettingsReader();
            string            key    = (string)reader.GetValue("secretYandexKey", typeof(string)); // секретный код
            // проверяем хэш
            string paramString = String.Format("{0}&{1}&{2}&{3}&{4}&{5}&{6}&{7}&{8}",
                                               notification_type, operation_id, amount, currency, datetime, sender,
                                               codepro.ToString().ToLower(), key, label);
            string paramStringHash1 = GetHash(paramString);

            // если хэши идентичны, добавляем данные о рекламе в бд
            if (paramStringHash1.Equals(sha1_hash))
            {
                bool     success        = false;
                DateTime expirationDate = DateTime.Now;
                switch (Convert.ToInt32(withdraw_amount)) //определяем по оплаченной сумме сколько времени будет висеть реклама
                {
                case 180: expirationDate = expirationDate.AddMonths(1); success = true; break;

                case 300: expirationDate = expirationDate.AddMonths(2); success = true; break;

                case 420: expirationDate = expirationDate.AddMonths(3); success = true; break;

                case 660: expirationDate = expirationDate.AddMonths(6); success = true; break;

                case 1020: expirationDate = expirationDate.AddYears(1); success = true; break;

                default: success = false; break;
                }

                if (success)
                {
                    //label - индитификатор платежа , в нем находиться id покупателя и id рекламного места (p2589123/j3242-dfs824-fdsf24)
                    string[] infoLabel   = label.Split('/');
                    string   imageId     = infoLabel[0];
                    string   userId      = infoLabel[1];
                    var      addAdResult = await _advertisingService.AddAdvertisingAsync(userId, imageId, expirationDate);
                }
            }
            return(new EmptyResult());
        }