public bool DeleteUser(User user) { try { UserTable.DeleteOnSubmit(user); UserTable.Context.SubmitChanges(); return true; } catch { return false; } }
public User GetUser(string login, string password) { SqlCeConnection conn = SQLQueryString.connection; conn.Open(); //Console.WriteLine("Connection is successfully made!"); try { string commandText = SQLQueryString.SelectUsersString; SqlCeCommand cmd = new SqlCeCommand(commandText, conn); cmd.Parameters.AddWithValue("@log", login); cmd.Parameters.AddWithValue("@pas", password); SqlCeDataReader dr = cmd.ExecuteReader(); User user; if (dr.Read()) { user = new User(); //Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", dr[0], dr[1], dr[2], dr[3], dr[4]); log.Info("User: "******" ID " + dr[0] + " NAME " + dr[1] + " ROLE " + (Role)dr[2] + " LOGIN " + dr[3] + " PASSWOR " + dr[4]); user.Id = (int)dr[0]; user.Name = (string)dr[1]; user.Role = (Role)dr[2]; user.Login = (string)dr[3]; user.Password = (string)dr[4]; return user; } return null; } catch (SqlCeException ex) { log.Error(ex.Message); return null; } finally { conn.Close(); } }
public static Order TranslateToOrder(ClientOrder clientOrder, User user) { if (clientOrder != null) { Order order = new Order(); order.Id = clientOrder.Id; order.PlacingDate = clientOrder.PlacingDate; order.Status = clientOrder.Status; order.User = user; if (clientOrder.Products != null) { order.Items = new List<OrderItem>(); for (int i = 0; i < clientOrder.Products.Count; i++) { order.Items.Add(TranslateToOrderItem(clientOrder.Products[i], order)); } } return order; } return null; }
public int SaveUser(User user) { try { if (user.UserId == 0) { UserTable.InsertOnSubmit(user); } else { UserTable.Context.Refresh(RefreshMode.KeepCurrentValues, user); } UserTable.Context.SubmitChanges(); return user.UserId; } catch { return -1; } }
public void saveUser(User user) { var User = (from b in _entities.Users where b.ID == user.ID select b).First(); User = user; //User.Logo = imgPath; _entities.SaveChanges(); }
/// <summary> /// Fills/Creates the user and the related entites with the data choosen by the User /// </summary> /// <param name="user">user entity to be modified</param> /// <param name="brandChoosen">List containing Id's of the Brands choosen</param> /// <param name="cultureChoosen">List containing Id's of the cultures choosen</param> /// <param name="regionChoosen">List containing Id's of the coutries choosen</param> /// <returns></returns> public User createdUserData(User user, List<Int32> brandChoosen, List<Int32> checkboxtree, List<Int32> cultureChoosen, List<Int32> regionChoosen) { User createdUser = new User(); createdUser.Username = user.Username; createdUser.Password = user.Password; createdUser.Active = user.Active; createdUser.Comment = user.Comment; createdUser.CountryID = user.CountryID; #region brand //createdUser.Brands.Load(); //createdUser.Brands.Clear(); if (brandChoosen != null) { List<Brand> BrandsAssct = createdUser.Brands.ToList(); foreach (var id in brandChoosen) { Brand inCheck = _entities.Brands.Where(brand => brand.ID == id).First(); if (!BrandsAssct.Contains(inCheck)) { createdUser.Brands.Add(inCheck); //editedUser.Brands.Attach(inCheck); } } } #endregion #region UserRights //createdUser.UICategories.Load(); //createdUser.UICategories.Clear(); if (checkboxtree != null) { List<UICategory> rightsAss = createdUser.UICategories.ToList(); foreach (var id in checkboxtree) { UICategory inCheck = _entities.UICategories.Where(cat => cat.ID == id).First(); if (!rightsAss.Contains(inCheck)) { createdUser.UICategories.Add(inCheck); //editedUser.Brands.Attach(inCheck); } } } #endregion #region Languages //createdUser.Cultures.Load(); //createdUser.Cultures.Clear(); if (cultureChoosen != null) { List<Culture> culturesAssct = createdUser.Cultures.ToList(); foreach (var id in cultureChoosen) { Culture inCheck = _entities.Cultures.Where(culture => culture.ID == id).First(); if (!culturesAssct.Contains(inCheck)) { createdUser.Cultures.Add(inCheck); //editedUser.Cultures.Attach(inCheck); } } } #endregion #region Regions //createdUser.Regions.Load(); //createdUser.Regions.Clear(); if (regionChoosen != null) { List<Region> regionsAssct = createdUser.Regions.ToList(); foreach (var id in regionChoosen) { Region inCheck = _entities.Regions.Where(region => region.ID == id).First(); if (!regionsAssct.Contains(inCheck)) { createdUser.Regions.Add(inCheck); } } } #endregion return createdUser; }
/// <summary> /// Gets all the details required for rendering the Edit UI /// </summary> public List<userRightdetails> getAllUserRightDetails(User user) { Dictionary<string, List<details>> allDetails = new Dictionary<string, List<details>>(); List<userRightdetails> userRightDetails = new List<userRightdetails>(); #region user detaild for Creating new User if (user == null) { #region get all Brands UICategory[] userRightsA = _entities.UICategories.ToArray(); foreach (var right in userRightsA) { userRightdetails userRightDetail; userRightDetail = new userRightdetails(right.ID, right.ParentID, right.LevelInTree, right.PositionInBranch, right.Name, false); userRightDetails.Add(userRightDetail); } #endregion } #endregion #region user detaild for Editing new User else { //Dictionary<string, List<details>> allDetails = new Dictionary<string, List<details>>(); User contextUser = _entities.Users.Where(userCnt => userCnt.ID == user.ID).First(); #region get all User rights //get all the existing User rights for the User contextUser.UICategories.Load(); //user.Brands.Load(); UICategory[] userRights = contextUser.UICategories.ToArray(); //get all the User rights for the User UICategory[] userRightsA = _entities.UICategories.ToArray(); //create custom list of User rights for the User //Add 'All' to the collection //userRightDetails.Add(new details(0, "All", false)); foreach (var right in userRightsA) { userRightdetails userRightDetail; if (userRights.Contains(right)) { userRightDetail = new userRightdetails(right.ID, right.ParentID, right.LevelInTree, right.PositionInBranch, right.Name, true); } else { userRightDetail = new userRightdetails(right.ID, right.ParentID, right.LevelInTree, right.PositionInBranch, right.Name, false); } userRightDetails.Add(userRightDetail); } #endregion } #endregion return userRightDetails; }
/// <summary> /// Gets all the details required for rendering the Edit UI /// </summary> public Dictionary<string, List<details>> getAllUserEditDetails(User user) { Dictionary<string, List<details>> allDetails = new Dictionary<string, List<details>>(); User contextUser = _entities.Users.Where(userCnt => userCnt.ID == user.ID).First(); #region get all Brands //get all the existing Brands for the User contextUser.Brands.Load(); //user.Brands.Load(); Brand[] userBrands = contextUser.Brands.OrderBy(brand => brand.Name).ToArray(); //get all the brands //Brand[] brandsAO = _entities.Brands.OrderBy(brand => brand.Name).ToArray(); Brand[] brandsA = (from b in _entities.Brands from c in b.Customers select b).ToArray(); //create custom list of brands List<details> brandsDetails = new List<details>(); //Add 'All' to the collection brandsDetails.Add(new details(0 , "All" ,false )); foreach (var brand in brandsA) { details brandDetail; if (userBrands.Contains(brand)) { brandDetail = new details(brand.ID, brand.Name , true); } else { brandDetail = new details(brand.ID, brand.Name, false); } brandsDetails.Add(brandDetail); } allDetails.Add("brands", brandsDetails); #endregion #region get all Languages //get all the existing cultures for the User contextUser.Cultures.Load(); Culture[] userCulture = contextUser.Cultures.OrderBy(culture => culture.Locale).ToArray(); //get all the cultures Culture[] culturesA = _entities.Cultures.Where(culture => culture.IsSupported == true).OrderBy(culture => culture.Locale).ToArray(); //create custom list of brands List<details> culturesDetails = new List<details>(); //Add 'All' to the collection culturesDetails.Add(new details(0, "All", false)); foreach (var culture in culturesA) { details cultureDetail; if (userCulture.Contains(culture)) { cultureDetail = new details(culture.ID, culture.Locale, true); } else { cultureDetail = new details(culture.ID, culture.Locale, false); } culturesDetails.Add(cultureDetail); } allDetails.Add("cultures", culturesDetails); #endregion #region get all Regions //get all the existing Regions for the User contextUser.Regions.Load(); Region[] userRegion = contextUser.Regions.OrderBy(region => region.Name).ToArray(); //get all the regions from the database Region[] regionsA = _entities.Regions.OrderBy(Region => Region.Name).ToArray(); //create custom list of regions List<details> regionsDetails = new List<details>(); //Add 'All' to the collection regionsDetails.Add(new details(0, "All", false)); foreach (var region in regionsA) { details regionDetail; if (userRegion.Contains(region)) { regionDetail = new details(region.ID, region.Name, true); } else { regionDetail = new details(region.ID, region.Name, false); } regionsDetails.Add(regionDetail); } allDetails.Add("regions", regionsDetails); #endregion return allDetails; }
/// <summary> /// Creates a new User /// </summary> /// <param name="newUser">User entity instance to be added</param> public void createUser(User newUser) { //var User = new User(); //var lastUser = _entities.Users.ToList().Last(); //User.ID = lastUser.ID + 1; //User.Username = name; //User.Logo = path; _entities.Users.AddObject(newUser); _entities.SaveChanges(); }
public User GetUser(int id, SqlCeConnection conn) { try { conn.Open(); string commandText = SQLQueryString.SelectUsers; SqlCeCommand cmd = new SqlCeCommand(commandText, conn); cmd.Parameters.AddWithValue("@id", id); SqlCeDataReader dr = cmd.ExecuteReader(); User user; if (dr.Read()) { user = new User(); user.Id = (int)dr[0]; user.Name = (string)dr[1]; user.Role = (Role)dr[2]; user.Login = (string)dr[3]; user.Password = (string)dr[4]; return user; } return null; } catch (SqlCeException ex) { log.Error(ex.Message); return null; } }
public void TranslateToOrderTest() { ClientOrder clientOrder = new ClientOrder() { Id = 1, PlacingDate = DateTime.Now, Status = Status.New, Products = new System.ComponentModel.BindingList<ClientOrderItem>() { new ClientOrderItem(1) { Count=5, Name="Test product 1", Price=100 }, new ClientOrderItem(2) { Count=2, Name="Test product 2", Price=200 } } }; User customer = new User() { Id = 111, Login = "******", Name = "Name", Password = "******", Role = Role.Customer }; Order order = EntitiesTranslator.TranslateToOrder(clientOrder, customer); Assert.AreEqual(order.Id,clientOrder.Id); Assert.AreEqual(order.PlacingDate,clientOrder.PlacingDate); Assert.AreEqual(order.User, customer); Assert.AreEqual(order.Status, clientOrder.Status); Assert.AreEqual(order.Items.Count, clientOrder.Products.Count); Assert.AreEqual(order.Items[0].Count, clientOrder.Products[0].Count); Assert.AreEqual(order.Items[0].Product.Name, clientOrder.Products[0].Name); Assert.AreEqual(order.Items[0].Product.Id, clientOrder.Products[0].Id); Assert.AreEqual(order.Items[1].Count, clientOrder.Products[1].Count); Assert.AreEqual(order.Items[1].Product.Name, clientOrder.Products[1].Name); Assert.AreEqual(order.Items[1].Product.Id, clientOrder.Products[1].Id); }