Пример #1
0
        public object ListOne(string IntermediaryCode)
        {
            SubscriptionsResponse bdr = new SubscriptionsResponse();

            try
            {
                using (var context = new DepContextSC())
                {
                    var parameters = new[] {
                        new SqlParameter("@IntermediaryCode", SqlDbType.VarChar)
                        {
                            Direction = ParameterDirection.Input, Value = IntermediaryCode
                        }
                    };
                    bdr.subscriptiondata = context.SubscriptionsFull.FromSqlRaw <SubscriptionsFull>("SP_ListSubscriptions @IntermediaryCode", parameters).ToList();
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Information("ListSubscriptionsError: " + e.Message);
                bdr.error = e.Message;
                //throw new Exception();
            }
            return(bdr);
        }
Пример #2
0
        private string GetNewNotificationToken()
        {
            var Authclient  = new RestClient("https://api-dev.sanlam.co.za/auth/oauth/v2/token");
            var Authrequest = new RestRequest(Method.POST);

            Authrequest.AddHeader("content-type", "application/x-www-form-urlencoded");
            Authrequest.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=l7401ccaea01034052abbda3d281b08d60&client_secret=0268a61963ca410a8181e1dc790c45e0", ParameterType.RequestBody);
            IRestResponse Authresponse = Authclient.Execute(Authrequest);
            TokenModel    token        = new TokenModel(Authresponse.Content);

            using (var tokencontext = new DepContextSC())
            {
                if (tokencontext.TempCache.Any(o => o.keyitem == "notificationtoken"))
                {
                    var updatetoken = tokencontext.TempCache.FirstOrDefault(e => e.keyitem == "notificationtoken");
                    updatetoken.valueitem = token.access_token;
                }
                else
                {
                    TempCache tx = new TempCache();
                    tx.keyitem   = "notificationtoken";
                    tx.valueitem = token.access_token;
                    tokencontext.TempCache.Add(tx);
                };
                tokencontext.SaveChanges();
            }

            return(token.access_token);
        }
Пример #3
0
        public IEnumerable <Subscriptions> NewSubscription(string IntermediaryCode, NewSubscriptionRequest bus)
        {
            using (var context = new DepContextSC())
            {
                string        tokenforCall = "";
                Subscriptions sub          = new Subscriptions();
                sub.IntermediaryCode = IntermediaryCode;
                sub.Serviceid        = bus.Serviceid;
                sub.Status           = bus.Status;

                context.Subscriptions.Add(sub);
                context.SaveChanges();

                if (context.TempCache.Any(o => o.keyitem == "notificationtoken"))
                {
                    TempCache bd = context.TempCache.Where(bus => bus.keyitem == "notificationtoken").FirstOrDefault();
                    tokenforCall = bd.valueitem;
                }
                else
                {
                    tokenforCall = GetNewNotificationToken();
                };
                string msg = "A new subscription was created IntermediaryCode: " + sub.IntermediaryCode + " with ServiceID: " + sub.Serviceid.ToString();

                if (SendEmailNotification(tokenforCall, msg, "New Subscription") == "valadationfail")
                {
                    tokenforCall = GetNewNotificationToken();

                    SendEmailNotification(tokenforCall, msg, "New Subscription");
                }
                ;

                return(context.Subscriptions.Where(bus => bus.IntermediaryCode == IntermediaryCode).ToList());
            }
        }
Пример #4
0
 public IEnumerable <Services> ListAllForThisCategory(int CategoryID)
 {
     using (var context = new DepContextSC())
     {
         return(context.Services.Where(bus => bus.Categoryid == CategoryID).ToList());
     }
 }
Пример #5
0
 public IEnumerable <Services> ListAll()
 {
     using (var context = new DepContextSC())
     {
         return(context.Services.ToList());
     }
 }
        public IEnumerable <Subscriptions> ListAll()
        {
            SubscriptionsResponse bdr = new SubscriptionsResponse();

            using (var context = new DepContextSC())
            {
                return(context.Subscriptions.Where(sub => sub.Status != "active").ToList());
            }
        }
Пример #7
0
        public object UpdateSubscriptions(int SubscriptionID, [FromBody] SubscriptionsRequest bus)
        {
            SubscriptionsResponse bdr = new SubscriptionsResponse();

            try
            {
                using (var context = new DepContextSC())
                {
                    string        tokenforCall = "";
                    Subscriptions bd           = context.Subscriptions.Where(bus => bus.Id == SubscriptionID).FirstOrDefault();
                    bd.Serviceid        = bus.Serviceid;
                    bd.IntermediaryCode = bus.IntermediaryCode;
                    bd.Status           = bus.Status;
                    context.SaveChanges();

                    if (bd.Status.ToLower() != "active")
                    {
                        if (context.TempCache.Any(o => o.keyitem == "notificationtoken"))
                        {
                            TempCache scr = context.TempCache.Where(bus => bus.keyitem == "notificationtoken").FirstOrDefault();
                            tokenforCall = scr.valueitem;
                        }
                        else
                        {
                            tokenforCall = GetNewNotificationToken();
                        };
                        string msg = "A subscription status was changed -  IntermediaryCode: " + bd.IntermediaryCode + " with ServiceID: " + bd.Serviceid.ToString();

                        if (SendEmailNotification(tokenforCall, msg, "Subscription cancellation") == "valadationfail")
                        {
                            tokenforCall = GetNewNotificationToken();

                            SendEmailNotification(tokenforCall, msg, "Subscription cancellation");
                        }
                        ;
                    }

                    bdr.subscriptiondata = context.Subscriptions.Where(bus => bus.Id == SubscriptionID).ToList();
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Information("UpdateSubscriptionsError: " + e.Message);
                bdr.error = e.Message;
                // throw new Exception();
            }
            return(bdr);
        }
Пример #8
0
        public IEnumerable <Services> UpdateServices(int id, Services bus)
        {
            try {
                using (var context = new DepContextSC())
                {
                    Services bd = context.Services.Where(bus => bus.Id == id).FirstOrDefault();
                    bd.Categoryid  = bus.Categoryid;
                    bd.Name        = bus.Name;
                    bd.Description = bus.Description;
                    bd.Cost        = bus.Cost;
                    bd.Terms       = bus.Terms;
                    bd.Status      = bus.Status;
                    context.SaveChanges();

                    return(context.Services.Where(bus => bus.Id == id).ToList());
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Information("UpdateServicesError: " + e.Message);
                throw new Exception();
            }
        }