public static int GetCountryCodeForIndia() { using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { return(db.WSR_Country.Where(x => x.CountryName == "India").Select(y => y.CountryCode).FirstOrDefault()); } }
public static bool AddCategory(string categoryName, string userName, string seoTitle, string seoDescription, string seoMetaKeywords) { List <WSR_ProductCategory> categoryList = new List <WSR_ProductCategory>(); WSR_ProductCategory newCategory = new WSR_ProductCategory { CategoryName = categoryName, CategoryUrl = null, CreatedBy = userName, CreatedDate = GetIndianTime(), EnabledDate = GetIndianTime(), EnabledBy = userName, IsActive = true, IsSubcategory = false, SeoTitle = seoTitle, SeoDescription = seoDescription, SeoMetaKeywords = seoMetaKeywords, }; using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { categoryList = db.WSR_ProductCategory.ToList(); bool categoryExists = categoryList.Where(x => x.IsSubcategory == false).Any(x => x.CategoryName.ToLower() == categoryName.ToLower()); if (categoryExists) { return(false); } else { db.WSR_ProductCategory.Add(newCategory); db.SaveChanges(); return(true); } } }
public static Product GetProductDetails(string productId) { using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { WSR_Product prod = db.WSR_Product.Where(x => x.ProductId.ToString() == productId).FirstOrDefault(); if (prod != null && !string.IsNullOrWhiteSpace(prod.Name)) { Product product = new Product { ProductId = prod.ProductId, Name = prod.Name, Image = prod.Image, SKU = prod.SKU, Description = prod.Description, BasePrice = prod.BasePrice, SalePrice = prod.SalePrice, SavingsAmount = prod.SavingsAmount, SavingsPercentage = prod.SavingsPercentage, SeoTitle = prod.SeoTitle, SeoDescription = prod.SeoDescription, SeoMetaKeywords = prod.SeoMetaKeywords, BasePriceString = prod.BasePriceString, SalePriceString = prod.SalePriceString, SavingsAmountString = prod.SavingsAmountString }; return(product); } else { return(null); } } }
public static bool AddSubcategory(int parentCategoryId, string userName, string subcategoryName, string subcategorySeoTitle, string subCategorySeoDesc, string subCategoryMetaKeywords) { List <WSR_ProductCategory> subCategoryList = new List <WSR_ProductCategory>(); WSR_ProductCategory newSubCategory = new WSR_ProductCategory { CategoryName = subcategoryName, CategoryUrl = null, ParentCategoryId = parentCategoryId, CreatedBy = userName, CreatedDate = GetIndianTime(), EnabledDate = GetIndianTime(), EnabledBy = userName, IsActive = true, IsSubcategory = true, SeoTitle = subcategorySeoTitle, SeoDescription = subCategorySeoDesc, SeoMetaKeywords = subCategoryMetaKeywords, }; using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { subCategoryList = db.WSR_ProductCategory.Where(x => x.ParentCategoryId == parentCategoryId && x.IsSubcategory == true).ToList(); bool subCategoryExists = subCategoryList.Where(x => x.ParentCategoryId == parentCategoryId && x.IsSubcategory == true).Any(x => x.CategoryName.ToLower() == subcategoryName.ToLower()); if (subCategoryExists) { return(false); } else { db.WSR_ProductCategory.Add(newSubCategory); db.SaveChanges(); return(true); } } }
public static void AddRolesToUser(Guid userId, List <string> roleIds) { string roles = string.Join(",", roleIds); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { db.WSR_Delete_And_Add_Roles_To_User(userId, roles); } }
public static string GetUserNameByUserId(string userId) { string userName; using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { userName = db.aspnet_Users.Where(x => x.UserId.ToString().ToLower() == userId.ToLower()).Select(y => y.UserName).FirstOrDefault(); } return(userName); }
public static List <WSR_ProductCategory> GetSubCategory(int categoryId) { List <WSR_ProductCategory> subCategoryList = new List <WSR_ProductCategory>(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { subCategoryList = db.WSR_ProductCategory.Where(x => x.ParentCategoryId == categoryId).ToList(); } return(subCategoryList); }
public static List <WSR_ProductCategory> GetAllCategoryDetails() { List <WSR_ProductCategory> categoryList = new List <WSR_ProductCategory>(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { categoryList = db.WSR_ProductCategory.Where(x => x.IsSubcategory == false).ToList(); } return(categoryList); }
public static List <aspnet_Roles> GetAllRoles() { List <aspnet_Roles> roles = new List <aspnet_Roles>(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { roles = db.aspnet_Roles.ToList(); } return(roles); }
public static List <RoleDetails> GetRoleDetails() { List <RoleDetails> roleDetails = new List <RoleDetails>(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { roleDetails = db.aspnet_Roles.Select(x => new RoleDetails { RoleId = x.RoleId.ToString(), RoleName = x.RoleName, RoleDescription = x.Description }).ToList(); } return(roleDetails); }
public static List <State> GetState(int countryCode) { List <State> stateList = new List <State>(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { stateList = db.WSR_State.Where(x => x.CountryCode == countryCode).Select (y => new State { StateCode = y.StateCode, StateName = y.StateName } ).ToList(); } return(stateList); }
public static List <City> GetCity(int stateCode) { List <City> cityList = new List <City>(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { cityList = db.WSR_City.Where(x => x.StateCode == stateCode).Select (y => new City { CityCode = y.CityCode, CityName = y.CityName } ).ToList(); } return(cityList); }
public static List <ListItem> GetAllUsers() { List <aspnet_Users> users = new List <aspnet_Users>(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { users = db.aspnet_Users.ToList(); } List <ListItem> listOfUsers = new List <ListItem>(); foreach (var eachUser in users) { ListItem li = new ListItem(); li.Text = eachUser.UserName; li.Value = eachUser.UserId.ToString(); listOfUsers.Add(li); } return(listOfUsers); }
public static void UpdateUserDetailsOnRegistration(string userName) { aspnet_Membership userMembership = new aspnet_Membership(); aspnet_Users aspUser = new aspnet_Users(); WSR_UserInfo newUser = new WSR_UserInfo(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { aspUser = db.aspnet_Users.Where(x => x.LoweredUserName == userName.ToLower()).FirstOrDefault(); userMembership = db.aspnet_Membership.Where(x => x.UserId == aspUser.UserId).FirstOrDefault(); if (aspUser != null && userMembership != null && aspUser.UserName.ToLower() == userName.ToLower() && aspUser.UserId == userMembership.UserId) { newUser.UserId = aspUser.UserId; newUser.UserName = aspUser.UserName; newUser.Email = userMembership.Email; db.WSR_UserInfo.Add(newUser); db.SaveChanges(); } } }
/// <summary> /// Get User Profile from Database /// </summary> /// <param name="userName">UserName</param> /// <returns>UserProfile with all details</returns> private static UserProfile GetUserProfile(string userName) { // If input userName is blank or the logged in user is if (string.IsNullOrWhiteSpace(userName)) { return(null); } else { userName = userName.ToLower(); } UserProfile userProfile = new UserProfile(); WSR_UserInfo userInfo = new WSR_UserInfo(); List <aspnet_Roles> allRoles = new List <aspnet_Roles>(); List <vw_aspnet_UsersInRoles> allUserRoles = new List <vw_aspnet_UsersInRoles>(); List <string> selectedRoles = new List <string>(); // Get all table values for the given user using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { userInfo = db.WSR_UserInfo.Where(x => x.UserName == userName).FirstOrDefault(); allRoles = db.aspnet_Roles.ToList(); allUserRoles = db.vw_aspnet_UsersInRoles.Where(x => x.UserId == userInfo.UserId).ToList(); } // Get all Role Names for the user and add in the List of selected Roles foreach (var userRole in allUserRoles) { string roleName = allRoles.Where(x => x.RoleId == userRole.RoleId).Select(y => y.RoleName).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(roleName)) { selectedRoles.Add(roleName); } } userProfile.UserInformation = userInfo; userProfile.UserRoles = selectedRoles; return(userProfile); }
public static List <ListItem> GetUserRoles(Guid userId) { List <ListItem> userRoles = new List <ListItem>(); List <Guid> userRoleIds = new List <Guid>(); List <aspnet_Roles> allRoles = GetAllRoles(); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { userRoleIds = db.vw_aspnet_UsersInRoles.Where(x => x.UserId == userId).Select(y => y.RoleId).ToList(); } foreach (var eachRole in allRoles) { ListItem li = new ListItem(); li.Text = eachRole.RoleName; li.Value = eachRole.RoleId.ToString(); li.Selected = userRoleIds.Where(x => x == eachRole.RoleId).Any(); userRoles.Add(li); } return(userRoles); }
public static void AddProduct(Product prod) { CultureInfo hindi = new CultureInfo("hi-IN"); //string currencySymbol = hindi.NumberFormat.CurrencySymbol; //string basePriceString = string.Format("{0} {1}", currencySymbol, string.Format(hindi, "{0:c}", prod.BasePrice)); //string salePriceString = string.Format("{0} {1}", currencySymbol, string.Format(hindi, "{0:c}", prod.SalePrice)); //string savingsAmountString = string.Format("{0} {1}", currencySymbol, string.Format(hindi, "{0:c}", prod.SavingsAmount)); string basePriceString = string.Format(hindi, "{0:c}", prod.BasePrice); string salePriceString = string.Format(hindi, "{0:c}", prod.SalePrice); string savingsAmountString = string.Format(hindi, "{0:c}", prod.SavingsAmount); using (WholesaleRajaEntities db = new WholesaleRajaEntities()) { WSR_Product dbProduct = new WSR_Product { Name = prod.Name, Image = prod.Image, SKU = prod.SKU, IsActive = prod.IsActive, Description = prod.Description, BasePrice = prod.BasePrice, SalePrice = prod.SalePrice, SavingsAmount = prod.SavingsAmount, SavingsPercentage = prod.SavingsPercentage, SeoTitle = prod.SeoTitle, SeoDescription = prod.SeoDescription, SeoMetaKeywords = prod.SeoMetaKeywords, CreatedDate = prod.CreatedDate, CreatedBy = prod.CreatedBy, BasePriceString = basePriceString, SalePriceString = salePriceString, SavingsAmountString = savingsAmountString }; db.WSR_Product.Add(dbProduct); db.SaveChanges(); } }