protected override string GetQuery(BaseProcessingModel model) { var shop = (ShopProcessingModel)model; return(string.Format( @" do $$ begin if (select 1 from ""Shop"" where ""Id""='{2}') then UPDATE ""public"".""Shop"" SET ""Name"" = '{0}', ""Code"" = '{1}' WHERE ""Id"" = '{2}'; ELSE INSERT INTO ""public"".""Shop"" (""Name"", ""Code"", ""Id"") VALUES ('{0}', '{1}', '{2}'); END IF; END $$ ", (shop.Name ?? "").Replace("'", "''"), (shop.Code ?? "").Replace("'", "''"), shop.Id)); }
protected override string GetQuery(BaseProcessingModel model) { var contact = (ContactProcessingModel)model; return(string.Format (@" do $$ begin if (select 1 from ""Contact"" where ""Id""='{2}') then UPDATE ""public"".""Contact"" SET ""Name"" = '{0}', ""Phone"" = '{1}', ""BrandId"" = '{3}' WHERE ""Id"" = '{2}'; ELSE INSERT INTO ""public"".""Contact"" (""Name"", ""Phone"", ""Id"", ""BrandId"") VALUES ('{0}', '{1}', '{2}', '{3}'); END IF; END $$ ", (contact.Name ?? "").Replace("'", "''"), (contact.Phone ?? "").Replace("'", "''"), contact.Id.ToString(), _defaultBrandId)); }
protected override string GetQuery(BaseProcessingModel model) { var c = (CardProcessingModel)model; return(string.Format( @" do $$ begin if (select 1 from ""Card"" where ""Id""='{0}') then UPDATE ""public"".""Card"" SET ""Number"" = '{1}', ""State"" = '{2}', ""IsMain"" = '{3}', ""ContactId"" = {4} WHERE ""Id"" = '{0}'; ELSE INSERT INTO ""public"".""Card"" (""Id"", ""Number"", ""State"", ""IsMain"", ""ContactId"") VALUES ('{0}', '{1}', '{2}', '{3}', {4}); END IF; END $$ ", c.CardId != "" ? c.CardId : c.Id.ToString(), (c.Number ?? "").Replace("'", "''"), c.State, c.IsMain, c.ContactId != "" ? string.Format("'{0}'", c.ContactId) : "null" )); }
protected override string GetQuery(BaseProcessingModel model) { var product = (ProductProcessingModel)model; var productCode = (product.Code ?? "").Replace("'", "''"); var price = product.Price.ToString().Replace(",", "."); return ($@" do $$ begin if (select 1 from ""Product"" where ""Id""='{product.Id}') then UPDATE ""public"".""Product"" SET ""Code"" = '{productCode}' WHERE ""Id"" = '{product.Id}'; ELSE INSERT INTO ""public"".""Product"" (""Code"", ""Id"") VALUES ('{productCode}', '{product.Id}'); END IF; if (select 1 from ""ProductRecommendedPrice"" where ""Code""='{productCode}') then UPDATE ""public"".""ProductRecommendedPrice"" SET ""Price"" = {price} WHERE ""Code"" = '{productCode}'; ELSE INSERT INTO ""public"".""ProductRecommendedPrice"" (""Price"", ""Code"") VALUES ('{price}', '{productCode}'); END IF; END $$"); }
protected abstract string GetQuery(BaseProcessingModel model);
protected override string GetQuery(BaseProcessingModel model) { var contact = (ContactProcessingModel)model; return(string.Format (@" do $$ begin if (select 1 from ""Contact"" where ""Id""='{2}') then UPDATE ""public"".""Contact"" SET ""Name_FirstName"" = '{0}', ""Phone"" = '{1}', ""BrandId"" = '{3}', ""Name_Surname"" = '{4}', ""Name_MiddleName"" = '{5}', ""Email"" = '{6}', ""Gender"" = '{7}', ""Address_Country"" = '{8}', ""Address_City"" = '{9}', ""Address_Address"" = '{10}', ""Birthday"" = {11}, ""CustomFields"" = '{{ ""SmrRequiresCorrection"": ""{12}"", ""SmrThereAreEmptyFields"": ""{13}"", ""SmrPersDataProcAgreement"": ""{14}""}}', ""RegistrationPlaceId"" = (SELECT ""Id"" FROM ""public"".""Shop"" WHERE ""Code"" = '{15}'), ""RegistrationDate"" = {16} WHERE ""Id"" = '{2}'; ELSE INSERT INTO ""public"".""Contact"" ( ""Name_FirstName"", ""Phone"", ""Id"", ""BrandId"", ""Name_Surname"", ""Name_MiddleName"", ""Email"", ""Gender"", ""Address_Country"", ""Address_City"", ""Address_Address"", ""Birthday"", ""CustomFields"", ""RegistrationPlaceId"", ""RegistrationDate"", ""PhoneConfirmed"" ) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', {11}, '{{ ""SmrRequiresCorrection"": ""{12}"", ""SmrThereAreEmptyFields"": ""{13}"", ""SmrPersDataProcAgreement"": ""{14}""}}', (SELECT ""Id"" FROM ""public"".""Shop"" WHERE ""Code"" = '{15}'), {16}, false); END IF; END $$ ", (contact.FirstName ?? String.Empty).Replace("'", "''"), (contact.Phone ?? String.Empty).Replace("'", "''"), contact.Id.ToString(), _defaultBrandId, (contact.Surname ?? String.Empty).Replace("'", "''"), (contact.MiddleName ?? String.Empty).Replace("'", "''"), (contact.Email ?? String.Empty).Replace("'", "''"), contact.Gender == "1" ? "0" : "1", (contact.Country ?? String.Empty).Replace("'", "''"), (contact.City ?? String.Empty).Replace("'", "''"), (contact.Address ?? String.Empty).Replace("'", "''"), String.IsNullOrEmpty(contact.Birthday) ? "null" : String.Format("'{0}'", contact.Birthday.Replace("'", "''")), (contact.RequiresCorrection ?? String.Empty).Replace("'", "''"), (contact.ThereAreEmptyFields ?? String.Empty).Replace("'", "''"), (contact.PersDataProcAgreement ?? String.Empty).Replace("'", "''"), (contact.ShopCode ?? String.Empty).Replace("'", "''"), String.IsNullOrEmpty(contact.RegistrationDate) ? "null" : String.Format("'{0}'", contact.RegistrationDate.Replace("'", "''")) )); }