Exemple #1
0
        public Response GetDataInDynamoDb(string affiliatename)
        {
            List <AffiliateDataModel>   Identities     = new List <AffiliateDataModel>();
            Dictionary <string, string> identityvalues = new Dictionary <string, string>();

            try
            {
                if (null == Table)
                {
                    return(new Response(false, "Table not Found"));
                }
                Document affiliateIdentity = Table.GetItem(affiliatename);
                if (null == affiliateIdentity)
                {
                    return(new Response(false, "Identity no more exist in database"));
                }
                string             json     = affiliateIdentity.ToJson();
                AffiliateDataModel identity = JsonConvert.DeserializeObject <AffiliateDataModel>(json);
                Identities.Add(identity);
                return(new Response(true, "Found Element", Identities));
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                return(new Response(false, exception.Message));
            }
        }
Exemple #2
0
        private List <AffiliateDataModel> CovertresponseIntoJSON(ScanResponse response)
        {
            List <Dictionary <string, AttributeValue> > result = response.Items;

            if (null == result)
            {
                return(null);
            }
            List <AffiliateDataModel> identityList      = new List <AffiliateDataModel>();
            AffiliateDataModel        affiliateIdentity = new AffiliateDataModel();
            List <string>             listofIdentites;

            foreach (Dictionary <string, AttributeValue> items in result)
            {
                listofIdentites = new List <string>();
                Dictionary <string, string>         item             = new Dictionary <string, string>();
                Dictionary <string, List <string> > websiteDataModel = new Dictionary <string, List <string> >();
                foreach (var val in items)
                {
                    if (val.Key.ToLower().Equals("identities"))
                    {
                        foreach (var web in val.Value.L)
                        {
                            listofIdentites.Add(web.S);
                        }
                    }
                    item.Add(val.Key, val.Value.S);
                }
                string jsonString = JsonConvert.SerializeObject(item, Formatting.Indented);
                affiliateIdentity            = JsonConvert.DeserializeObject <AffiliateDataModel>(jsonString);
                affiliateIdentity.Identities = listofIdentites;
                identityList.Add(affiliateIdentity);
            }
            return(identityList);
        }
Exemple #3
0
 public Response SaveDataInDynamoDb(AffiliateDataModel affiliate)
 {
     try
     {
         if (null == Table)
         {
             return(new Response(false, "Table not Found"));
         }
         var affiliatename = Table.GetItem(affiliate.Name);
         if (null == affiliatename)
         {
             Response responseIdentity                   = AmazonDynamoDBIdentityTable.Instance.GetAllDataInDynamoDb();
             List <IdentityDataModel> Identities         = responseIdentity.IdentityDataModel;
             List <string>            affiliateIdentites = new List <string>();
             foreach (var identity in Identities)
             {
                 if (null != identity.Affiliate && identity.Affiliate.ToLower().Equals(affiliate.Name.ToLower()))
                 {
                     affiliateIdentites.Add(identity.Email);
                 }
             }
             affiliate.Identities = affiliateIdentites;
             string   jsonText = JsonConvert.SerializeObject(affiliate);
             var      item     = Document.FromJson(jsonText);
             Document response = Table.PutItem(item);
             return(new Response(true, null));
         }
         return(new Response(false, "Identity already Exist"));
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         return(new Response(false, exception.Message));
     }
 }
Exemple #4
0
        internal AffiliateDataModel SetEmptyValuestoNull(AffiliateDataModel affiliateidentity)
        {
            List <WebsiteDataModel> list = new List <WebsiteDataModel>();

            affiliateidentity.Name       = string.IsNullOrEmpty(affiliateidentity.Name) ? " " : affiliateidentity.Name;
            affiliateidentity.Identities = new List <string>();
            return(affiliateidentity);
        }
Exemple #5
0
 public Response UpdateDataInDynamoDb(AffiliateDataModel affiliate, string identityDataEmail = null)
 {
     try
     {
         if (null == Table)
         {
             return(new Response(false, "Table not Found"));
         }
         Document identityemail = Table.GetItem(affiliate.Name);
         if (null != identityemail)
         {
             if (null != identityDataEmail)
             {
                 Response result = GetAllDataInDynamoDb();
                 foreach (AffiliateDataModel value in result.AffiliateDataModel)
                 {
                     if (value.Identities.Contains(identityDataEmail))
                     {
                         value.Identities.Remove(identityDataEmail);
                         string   json = JsonConvert.SerializeObject(value);
                         Document val  = Document.FromJson(json);
                         Table.UpdateItem(val);
                     }
                 }
             }
             Response responseIdentity                   = AmazonDynamoDBIdentityTable.Instance.GetAllDataInDynamoDb();
             List <IdentityDataModel> Identities         = responseIdentity.IdentityDataModel;
             List <string>            affiliateIdentites = new List <string>();
             foreach (var identity in Identities)
             {
                 if (null != identity.Affiliate && identity.Affiliate.ToLower().Equals(affiliate.Name.ToLower()))
                 {
                     affiliateIdentites.Add(identity.Email);
                 }
             }
             affiliate.Identities = affiliateIdentites;
             string   jsonText = JsonConvert.SerializeObject(affiliate);
             Document item     = Document.FromJson(jsonText);
             Document response = Table.UpdateItem(item);
             return(new Response(true, null));
         }
         return(new Response(false, "Identity no more exist in database"));
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         return(new Response(false, exception.Message));
     }
 }
Exemple #6
0
        internal AffiliateDataModel ConvertToLowerCase(AffiliateDataModel identityData)
        {
            List <string> list = new List <string>();

            identityData.Name = identityData.Name.ToLower();
            if (identityData.Identities.Count > 0)
            {
                foreach (var website in identityData.Identities)
                {
                    list.Add(website.ToLower());
                }
                identityData.Identities = list;
            }
            return(identityData);
        }
Exemple #7
0
        internal AffiliateDataModel ConvertToTitleCase(AffiliateDataModel affiliateidentity)
        {
            TextInfo      textInfo = new CultureInfo("en-US", false).TextInfo;
            List <string> list     = new List <string>();

            affiliateidentity.Name = textInfo.ToTitleCase(affiliateidentity.Name);
            if (affiliateidentity.Identities.Count > 0)
            {
                foreach (var website in affiliateidentity.Identities)
                {
                    list.Add(textInfo.ToTitleCase(website));
                }
                affiliateidentity.Identities = list;
            }
            return(affiliateidentity);
        }