Esempio n. 1
0
 public async Task <ReplaceOneResult> UpdateBillerCategory(string id, BillerCategory item)
 {
     return(await _context.BillerCategories
            .ReplaceOneAsync(n => n._id.Equals(id)
                             , item
                             , new UpdateOptions { IsUpsert = true }));
 }
        public async Task <BillerCategory> AddBillerCategory(BillerCategory item)
        {
            await _context.BillersCategory.AddAsync(item);

            await _context.SaveChangesAsync();

            return(await GetBillerCategory(item._id));
        }
        public async Task <BillerCategory> UpdateBillerCategory(BillerCategory billercategory)
        {
            BillerCategory bc = await GetBillerCategory(billercategory._id);

            bc.title  = billercategory.title;
            bc.status = billercategory.status;

            await _context.SaveChangesAsync();

            return(bc);
        }
Esempio n. 4
0
        public async Task setbillercategory(string key, BillerCategory categories, CancellationToken cts)
        {
            try
            {
                var category = await redis.GetStringAsync(key);

                if (!string.IsNullOrEmpty(category))
                {
                    redis.Remove(key);
                }
                string value = JsonHelper.toJson(categories);

                await redis.SetStringAsync(key, value, cts);
            }
            catch (Exception)
            {
            }
        }
Esempio n. 5
0
        public async Task <BillerCategory> getbillercategory(string key, CancellationToken ctx)
        {
            BillerCategory categories = new BillerCategory();

            try
            {
                var category = await redis.GetStringAsync(key, ctx);

                if (!string.IsNullOrEmpty(category))
                {
                    categories = JsonHelper.fromJson <BillerCategory>(category);
                }
            }
            catch (Exception)
            {
            }
            return(categories);
        }
Esempio n. 6
0
        public async Task <IActionResult> addbillercategory([FromBody] BillerCategory billercategory)
        {
            BillerCategory        _billercategory  = null;
            List <BillerCategory> billercategories = null;
            BillerCategoryError   e = new BillerCategoryError();
            Redis redis             = new Redis(settings, cache);

            CancellationTokenSource cts;

            cts = new CancellationTokenSource();
            cts.CancelAfter(settings.Value.redisCancellationToken);

            //validate request
            if (!ModelState.IsValid)
            {
                var modelErrors = new List <BillerCategoryError>();
                var eD          = new List <string>();
                foreach (var modelState in ModelState.Values)
                {
                    foreach (var modelError in modelState.Errors)
                    {
                        eD.Add(modelError.ErrorMessage);
                    }
                }
                e.error        = ((int)HttpStatusCode.BadRequest).ToString();
                e.errorDetails = eD;

                return(BadRequest(e));
            }
            billercategory.created_on = DateTime.Now;
            //Add to mongo
            try
            {
                //_billercategory = await billercategoryMongoRepo.AddBillerCategory(billercategory);
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            //Add to sql server
            try
            {
                if (billercategory._id == 0)
                {
                    _billercategory = await billercategorySqlRepo.AddBillerCategory(billercategory);
                }
                else if (billercategory._id > 0)
                {
                    _billercategory = await billercategorySqlRepo.UpdateBillerCategory(billercategory);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            //Write to Redis
            try
            {
                string key = "all_biller_category:" + _billercategory._id;

                if (_billercategory != null)
                {
                    await redis.setbillercategory(key, _billercategory, cts.Token);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            return(CreatedAtAction("addbillercategory", _billercategory));
        }
Esempio n. 7
0
        public async Task <BillerCategory> AddBillerCategory(BillerCategory item)
        {
            await _context.BillerCategories.InsertOneAsync(item);

            return(await GetBillerCategory(item._id));
        }