public void ActivateEmailTest()
 {
     var repository = new CustomerRepositoryHelper();
     var customer = new CustomerData
                    {
                        LicenseId = "123"
                    };
     Console.WriteLine(repository.ActivateEmail(customer));
 }
 public void UpdateCustomer()
 {
     var repository = new CustomerRepositoryHelper();
     var customer = new CustomerData
                    {
                        LicenseId = "123",
                        FirstName = "Sergei1",
                        LastName = "oak2",
                        DateOfBirth = DateTime.Now.Date.ToString("yyyyMMdd"),
                        Email = "[email protected]",
                        IsEmailVerified = false,
                        Timezone = "UTC4",
                        HashPass = "******",
                        PaymentProfile = "test6",
                        Expires = DateTime.Now,
                        Obs = "7",
                        Status = "8",
                        Type = "9"
                    };
     Console.WriteLine(repository.UpdateCustomer(customer));
 }
 public void InsertCustomerTest()
 {
     var customer = new CustomerData
                    {
                        LicenseId = "123",
                        FirstName = "Sergei",
                        LastName = "oak",
                        DateOfBirth = DateTime.Now.Date.ToString("yyyyMMdd"),
                        Email = "*****@*****.**",
                        IsEmailVerified = false,
                        Timezone = "UTC",
                        HashPass = "******",
                        PaymentProfile = "test",
                        Expires = DateTime.Now,
                        Obs = "",
                        Status = "",
                        Type = ""
                    };
     var repository = new CustomerRepositoryHelper();
     string licenseId;
     Console.WriteLine(repository.InsertCustomer(customer, out licenseId));
 }
        /// <summary>
        /// Create New Customer
        /// </summary>
        public Boolean InsertCustomer(CustomerData customerData, out string licenseId)
        {
            var customer = new Customer
                           {
                               LicenseId = customerData.LicenseId,
                               FirstName = customerData.FirstName,
                               LastName = customerData.LastName,
                               DateOfBirth = customerData.DateOfBirth,
                               Email = AESHelper.Encrypt(customerData.Email),
                               IsEmailVerified = false,
                               Timezone = customerData.Timezone,
                               Hashpass = AESHelper.Encrypt(customerData.HashPass),
                               PaymentProfile = customerData.PaymentProfile,
                               Expires = customerData.Expires,
                               Obs = customerData.Obs,
                               Status = customerData.Status,
                               Type = customerData.Type,
                               Created = DateTime.UtcNow,
                               Updated = DateTime.UtcNow,
                               Version = "1.0"
                           };

            using (var context = new CustomerInfoRepository())
            {
                context.Customers.Add(customer);
                try
                {
                    context.SaveChanges();
                    licenseId = customerData.LicenseId;
                    return true;
                }
                catch (Exception)
                {
                    licenseId = "";
                    return false;
                }
            }
        }
        /// <summary>
        /// Update IsEmailVerified flag to True
        /// </summary>
        public Customer ActivateEmail(CustomerData customerData)
        {
            using (var context = new CustomerInfoRepository())
            {
                var user = context.Customers.FirstOrDefault(x => x.LicenseId == customerData.LicenseId);
                if (user != null)
                {
                    user.Updated = DateTime.UtcNow;
                    user.IsEmailVerified = true;

                    try
                    {
                        context.SaveChanges();
                        return user;
                    }
                    catch (Exception)
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }
        }
        public Customer UpdateCustomer(CustomerData customerData)
        {
            using (var context = new CustomerInfoRepository())
            {
                var updating = context.Customers.FirstOrDefault(x => x.LicenseId == customerData.LicenseId);
                if (updating != null)
                {
                    if (customerData.FirstName != null) updating.FirstName = customerData.FirstName;
                    if (customerData.LastName != null) updating.LastName = customerData.LastName;
                    if (customerData.Email != null) updating.Email = AESHelper.Encrypt(customerData.Email);
                    if (customerData.Timezone != null) updating.Timezone = customerData.Timezone;
                    if (customerData.HashPass != null) updating.Hashpass = AESHelper.Encrypt(customerData.HashPass);
                    if (customerData.PaymentProfile != null) updating.PaymentProfile = customerData.PaymentProfile;
                    if (customerData.Expires != DateTime.MinValue) updating.Expires = customerData.Expires;
                    if (customerData.DateOfBirth != null) updating.DateOfBirth = customerData.DateOfBirth;
                    if (customerData.Obs != null) updating.Obs = customerData.Obs;
                    if (customerData.Status != null) updating.Status = customerData.Status;
                    if (customerData.Type != null) updating.Type = customerData.Type;

                    try
                    {
                        context.SaveChanges();
                        return updating;
                    }
                    catch (Exception)
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }
        }