CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.Entity;
using System.Diagnostics;
using MySql.Data.MySqlClient;
using MySql.Data.Entity;
namespace ExternalCustomerSoapServer
{
public class ExternalSoapCustomerService : IExternalSoapCustomerService
{
CustomerInformation CreateCustomerInfo(CUST cust)
{
return new CustomerInformation
{
CardNumber = cust.CARD_NUMBER,
Name = cust.NAME,
SurName = cust.SURNAME,
};
}
public CustomerInformation GetCustomerInformation(string CardNumber)
{
using (var db = new SELFSCANEntities())
{
List<CUST> list = db.CUST.Where(c => c.CARD_NUMBER.Equals(CardNumber)).ToList();
if (list.Count > 0)
{
return CreateCustomerInfo(list[0]);
}
}
return new CustomerInformation();
}
public CustomerInformation[] GetCustomerInformationArray(SearchCriteria[] criteria, long offset, long count)
{
List<CustomerInformation> result = new List<CustomerInformation>();
try
{
using (var db = new XXXEntities())
{
StringBuilder whereString = new StringBuilder();
foreach (SearchCriteria crit in criteria)
{
whereString.Append(crit.CriteriaOperator + " " + "it." + crit.FieldName + " " + crit.FieldOperator + " " + crit.FieldValue + " ");
}
var query = (db.CUST
.Where(whereString.ToString())
.OrderBy("it.CARD_NUMBER")
).Skip((int)offset).Take((int)count);
foreach (CUST cust in query)
{
result.Add(CreateCustomerInfo(cust));
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
return result.ToArray();
}
}
}