public bool AddNewCoustomer(CustomerBasicDetails customerBasicDetails, Guid customerId) { try { using (var dataContext = new BrownBagDataEntities()) { var customer = new BrownBagService.DataAccess.DataEntity.Customer { Active = 0, AdminComment = null, AffiliateId = 0, IsTaxExempt = 0, VendorId = 0, CannotLoginUntilDateUtc = DateTime.Now.ToUniversalTime(), Deleted = 0, Email = customerBasicDetails.Email.Trim(), EmailToRevalidate = null, Username = customerBasicDetails.Email.Trim(), CustomerGuid = customerId, BillingAddress_Id = null, FailedLoginAttempts = 0, HasShoppingCartItems = 0, IsSystemAccount = 0, ShippingAddress_Id = null, LastActivityDateUtc = DateTime.Now.ToUniversalTime(), LastIpAddress = null, LastLoginDateUtc = null, RequireReLogin = 0, RegisteredInStoreId = 1, SystemName = null, CreatedOnUtc = DateTime.Now.ToUniversalTime(), }; dataContext.Customers.Add(customer); int rowCount = dataContext.SaveChanges(); if (rowCount > 0) { dataContext.Customer_CustomerRole_Mapping.Add(new Customer_CustomerRole_Mapping { CustomerRole_Id = 3, Customer_Id = customer.Id }); } return(dataContext.SaveChanges() > 0 ? true : false); } } catch { throw; } }
public bool VerifyOTP(string otp, string email) { try { using (var dataContext = new BrownBagDataEntities()) { DateTime currentTime = DateTime.Now.ToUniversalTime(); var latestOtp = dataContext.OtpDetails .Where(a => a.Email == email && a.OTP == otp && a.IsActive == true && a.IsVerified == false && a.IssueDate <currentTime && a.ExpiryDate> currentTime) .OrderByDescending(o => o.Id).FirstOrDefault(); if (latestOtp != null) { latestOtp.IsActive = false; latestOtp.IsVerified = true; int rows = dataContext.SaveChanges(); if (rows > 0) { var customer = dataContext.Customers.Where(a => a.CustomerGuid == latestOtp.RefCustomerGuid).FirstOrDefault(); if (customer != null) { customer.Active = 1; customer.LastActivityDateUtc = DateTime.Now.ToUniversalTime(); dataContext.SaveChanges(); } var customerProfile = dataContext.CustomerAttributes.Where(a => a.Customer_Id == latestOtp.RefCustomerGuid).FirstOrDefault(); if (customerProfile != null) { customerProfile.OTP_Verified = 1; customerProfile.Modified_Date = DateTime.Now.ToUniversalTime(); dataContext.SaveChanges(); } } return(true); } else { return(false); } } } catch { throw; } }
public bool ChangeCustomerPassword(string deviceId, string password, string email) { try { bool isSave = false; using (var dataContext = new BrownBagDataEntities()) { if (!string.IsNullOrEmpty(deviceId) && string.IsNullOrEmpty(email)) { var deviceData = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceId).FirstOrDefault(); if (deviceData != null) { var passwordDetails = dataContext.CustomerPasswords.Where(a => a.CustomerId == deviceData.RefCustomerGuid).FirstOrDefault(); passwordDetails.Password = password; } } else if (string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(email)) { var emailData = dataContext.Customers.Where(a => a.Email == email).FirstOrDefault(); if (emailData != null) { var passwordDetails = dataContext.CustomerPasswords.Where(a => a.CustomerId == emailData.CustomerGuid ).FirstOrDefault(); passwordDetails.Password = password; } } isSave = dataContext.SaveChanges() > 0 ? true : false; } return(isSave); } catch { throw; } }
public bool CustomerLogOff(string deviceId) { try { bool isLogOff = false; using (var dataContext = new BrownBagDataEntities()) { if (!string.IsNullOrEmpty(deviceId)) { var deviceData = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceId).FirstOrDefault(); if (deviceData != null) { isLogOff = true; deviceData.RefCustomerGuid = null; deviceData.UpdatedOnUtc = DateTime.Now.ToUniversalTime(); } } isLogOff = dataContext.SaveChanges() > 0 ? true : false; } return(isLogOff); } catch { throw; } }
public bool CustomerLogIn(string deviceId, string password, string email) { try { bool isLogin = false; using (var dataContext = new BrownBagDataEntities()) { if (!string.IsNullOrEmpty(deviceId) && !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password)) { var deviceData = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceId).FirstOrDefault(); var customerData = dataContext.Customers.Where(a => a.Email == email).FirstOrDefault(); if (customerData != null) { var passwordData = dataContext.CustomerPasswords.Where(a => a.Password == password && a.CustomerId == customerData.CustomerGuid).FirstOrDefault(); if (deviceData != null && passwordData != null) { isLogin = true; deviceData.RefCustomerGuid = customerData.CustomerGuid; } } } isLogin = dataContext.SaveChanges() > 0 ? true : false; } return(isLogin); } catch { throw; } }
public bool AddNewAddress(Model.CustomerDetailAttribute customerAddress) { try { using (var dataContext = new BrownBagDataEntities()) { dataContext.CustomerAttributes.Add(new DataEntity.CustomerAttribute { Customer_Id = customerAddress.Customer_Id, Customer_Email = customerAddress.Customer_Email, Customer_Phone = customerAddress.Customer_Phone, OTP_Verified = 0, Modified_Date = DateTime.Now.ToUniversalTime(), Customer_Name = customerAddress.Customer_Name, Customer_Active = customerAddress.Customer_Active, Created_Date = DateTime.Now.ToUniversalTime(), Created_By = customerAddress.Customer_Email }); return(dataContext.SaveChanges() > 0 ? true : false); } } catch { throw; } }
public bool AddNewOTP(OtpDetailsModel OtpDetailsModel) { try { using (var dataContext = new BrownBagDataEntities()) { dataContext.OtpDetails.Add(new DataEntity.OtpDetail { Email = OtpDetailsModel.Email, ExpiryDate = OtpDetailsModel.ExpiryDate, IsActive = OtpDetailsModel.IsActive, IsVerified = OtpDetailsModel.IsVerified, OTP = OtpDetailsModel.OTP, Prupose = OtpDetailsModel.Prupose, IssueDate = OtpDetailsModel.IssueDate, RefCustomerGuid = OtpDetailsModel.RefCustomerGuid }); return(dataContext.SaveChanges() > 0 ? true : false); } } catch { throw; } }
public bool EditDeviceRegistration(DeviceRegistrationModel device) { try { using (var dataContext = new BrownBagDataEntities()) { var selectedDevice = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == device.IMEINumber).FirstOrDefault(); if (selectedDevice != null) { selectedDevice.AccessToken = device.AccessToken.Trim(); selectedDevice.UpdatedOnUtc = DateTime.Now.ToUniversalTime(); return(dataContext.SaveChanges() > 0 ? true : false); } else { return(false); } } } catch { throw; } }
public bool AddDeviceRegistration(DeviceRegistrationModel device) { try { using (var dataContext = new BrownBagDataEntities()) { var deviceRegistration = new DeviceRegistration { AccessToken = device.AccessToken.Trim(), CreatedOnUtc = DateTime.Now.ToUniversalTime(), IMEI_Number = device.IMEINumber.Trim(), IsActive = true, RefCustomerGuid = string.IsNullOrEmpty(device.CustomerGuid) ? (Guid?)null : Guid.Parse(device.CustomerGuid), UpdatedOnUtc = DateTime.Now.ToUniversalTime() }; dataContext.DeviceRegistrations.Add(deviceRegistration); return(dataContext.SaveChanges() > 0 ? true : false); } } catch { throw; } }
public bool AddToCart(int productId, CurrencyTypeName currencyTypeName, string deviceNumber) { try { using (var dataContext = new BrownBagDataEntities()) { var userInfo = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceNumber).FirstOrDefault(); if (userInfo != null && userInfo.RefCustomerGuid != null) { var product = dataContext.Products.Where(a => a.Id == productId).FirstOrDefault(); if (product != null) { if (product.Stock > 0) { var itemPrice = (currencyTypeName == CurrencyTypeName.INR) ? product.CP_INR ?? 0 : (currencyTypeName == CurrencyTypeName.USD) ? product.CP_USD ?? 0 : (currencyTypeName == CurrencyTypeName.EURO) ? product.CP_Euro ?? 0 : product.CP_GBP ?? 0; ShoppingCartItem cartItem = new ShoppingCartItem { CreatedOnUtc = DateTime.Now.ToUniversalTime(), UpdatedOnUtc = DateTime.Now.ToUniversalTime(), Currency = currencyTypeName.ToString(), Customer_Id = userInfo.RefCustomerGuid.Value, ProductId = productId, ProductPrice = itemPrice, Quantity = 1, RevisedPrice = 0 }; dataContext.ShoppingCartItems.Add(cartItem); return(dataContext.SaveChanges() > 0 ? true : false); } else { return(false); } } else { return(false); } } else { return(false); } } } catch { throw; } }
public bool DeleteAddress(string deviceNo, int id) { try { using (var dataContext = new BrownBagDataEntities()) { var device = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceNo).FirstOrDefault(); if (device == null) { return(false); } if (device.RefCustomerGuid == null) { return(false); } var address = dataContext.Addresses .Where(a => a.Id == id && a.CustomerGUID == device.RefCustomerGuid && a.Status == 1) .FirstOrDefault(); var relatedDetail = dataContext.Customers .Where(a => a.CustomerGuid == device.RefCustomerGuid && a.ShippingAddress_Id == address.Id || a.BillingAddress_Id == address.Id) .FirstOrDefault(); if (relatedDetail != null) { if (relatedDetail.BillingAddress_Id == address.Id) { relatedDetail.BillingAddress_Id = null; } if (relatedDetail.ShippingAddress_Id == address.Id) { relatedDetail.ShippingAddress_Id = null; } } dataContext.Addresses.Remove(address); dataContext.SaveChanges(); return(true); } } catch { throw; } }
public bool AddNewCustomerPassword(Guid customerId, string password) { try { using (var dataContext = new BrownBagDataEntities()) { dataContext.CustomerPasswords.Add(new DataEntity.CustomerPassword { CustomerId = customerId, Password = password, PasswordFormatId = 1, CreatedOnUtc = DateTime.Now.ToUniversalTime(), }); return(dataContext.SaveChanges() > 0 ? true : false); } } catch { throw; } }
public bool UpdateOTP(OtpDetailsModel OtpDetailsModel) { try { using (var dataContext = new BrownBagDataEntities()) { var otp = dataContext.OtpDetails.Where(a => a.Id == OtpDetailsModel.Id).FirstOrDefault(); otp.ExpiryDate = OtpDetailsModel.ExpiryDate; otp.IsActive = OtpDetailsModel.IsActive; otp.IsVerified = OtpDetailsModel.IsVerified; otp.IssueDate = OtpDetailsModel.IssueDate; return(dataContext.SaveChanges() > 0 ? true : false); } } catch { throw; } }
public bool DeleteDeviceRegistration(string deviceId) { try { using (var dataContext = new BrownBagDataEntities()) { var selectedDevice = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceId).FirstOrDefault(); if (selectedDevice != null) { dataContext.DeviceRegistrations.Remove(selectedDevice); return(dataContext.SaveChanges() > 0 ? true : false); } else { return(false); } } } catch { throw; } }
public bool RemoveFromCart(int productId, string deviceNumber) { try { using (var dataContext = new BrownBagDataEntities()) { var userInfo = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceNumber).FirstOrDefault(); if (userInfo != null && userInfo.RefCustomerGuid != null) { var product = dataContext.Products.Where(a => a.Id == productId).FirstOrDefault(); if (product != null) { var item = dataContext.ShoppingCartItems.Where(a => a.ProductId == productId && a.Customer_Id == userInfo.RefCustomerGuid.Value).FirstOrDefault(); if (item != null) { dataContext.ShoppingCartItems.Remove(item); return(dataContext.SaveChanges() > 0 ? true : false); } return(false); } else { return(false); } } else { return(false); } } } catch { throw; } }
public bool SaveBillingAddress(CustomerBillingAddress customerBillingAddress, string deviceNo) { try { using (var dataContext = new BrownBagDataEntities()) { var addressEntity = new DataEntity.Address(); var device = dataContext.DeviceRegistrations.Where(a => a.IMEI_Number == deviceNo).FirstOrDefault(); if (device == null) { return(false); } if (device.RefCustomerGuid == null) { return(false); } var customerOtherDetails = dataContext.CustomerAttributes.Where(a => a.Customer_Id == device.RefCustomerGuid).FirstOrDefault(); if (customerOtherDetails == null) { return(false); } var nameSegments = customerOtherDetails.Customer_Name.Split(' '); var firstName = ""; for (int i = 0; i < nameSegments.Length - 1; i++) { firstName += nameSegments[i].Trim() + " "; } if (customerBillingAddress != null) { if (customerBillingAddress.Id == 0) { addressEntity = new DataEntity.Address { Country = customerBillingAddress.Country, CompanyName = "", City = customerBillingAddress.City ?? "", State = customerBillingAddress.State ?? "", StreetAddress1 = customerBillingAddress.StreetAddress1, StreetAddress2 = customerBillingAddress.StreetAddress2 ?? "", ZipCode = customerBillingAddress.ZipCode ?? "", CreatedOnUtc = DateTime.Now.ToUniversalTime(), UpdatedOnUtc = DateTime.Now.ToUniversalTime(), Status = 1, CustomerGUID = device.RefCustomerGuid, FirstName = firstName.Trim(), LastName = nameSegments[nameSegments.Length - 1].Trim() }; dataContext.Addresses.Add(addressEntity); } else { var selectedAddress = dataContext.Addresses.Where(a => a.Id == customerBillingAddress.Id).FirstOrDefault(); if (selectedAddress != null) { selectedAddress.Country = customerBillingAddress.Country ?? ""; selectedAddress.City = customerBillingAddress.City ?? ""; selectedAddress.State = customerBillingAddress.State ?? ""; selectedAddress.StreetAddress1 = customerBillingAddress.StreetAddress1 ?? ""; selectedAddress.StreetAddress2 = customerBillingAddress.StreetAddress2 ?? ""; selectedAddress.ZipCode = customerBillingAddress.ZipCode ?? ""; selectedAddress.CreatedOnUtc = DateTime.Now.ToUniversalTime(); selectedAddress.UpdatedOnUtc = DateTime.Now.ToUniversalTime(); } } } var isSave = dataContext.SaveChanges() > 0 ? true : false; if (customerBillingAddress.Id == 0 && dataContext.Addresses.Where(x => x.CustomerGUID == device.RefCustomerGuid).Count() == 1) { var customer = dataContext.Customers.Where(a => a.CustomerGuid == device.RefCustomerGuid).FirstOrDefault(); customer.ShippingAddress_Id = addressEntity.Id; customer.BillingAddress_Id = addressEntity.Id; dataContext.SaveChanges(); } return(isSave); } } catch { throw; } }