private void btnaccept_Click(object sender, EventArgs e) { if (txtpassword.Text == string.Empty || txtusername.Text == string.Empty) { MessageBox.Show("اطلاعات وارد شده درست نمی باشد .", "پیام سیستم", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { var contaxt = new DataLayer.InventoryDBContext(); var relateduser = contaxt.Users.FirstOrDefault(u => u.Username.Equals(txtusername.Text)); if (relateduser == null) { MessageBox.Show("نام کاربری وجود ندارد .", "پیام سیستم", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { var saltedPassword = txtpassword.Text + relateduser.PasswordSalt; var saltedPasswordBytes = System.Text.Encoding.UTF8.GetBytes(saltedPassword); var hashedPassword = Convert.ToBase64String(SHA512.Create().ComputeHash(saltedPasswordBytes)); if (!hashedPassword.Equals(relateduser.Password)) { MessageBox.Show("کلمه عبور نادرست است .", "پیام سیستم", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { var identity = new GenericIdentity(relateduser.Username); var roles = relateduser.Roles.Select(p => p.Title).ToArray(); var principal = new GenericPrincipal(identity, roles); System.Threading.Thread.CurrentPrincipal = principal; DialogResult = DialogResult.OK; } } } }
public User Find(int id) { try { var contaxt = new DataLayer.InventoryDBContext(); return(contaxt.Users.FirstOrDefault(p => p.UserId == id)); } catch { return(null); } }
public ICollection <User> Search(UserSearchType SearchType, string value) { List <InventoryApp.Entities.User> List = new List <Entities.User>(); var contaxt = new DataLayer.InventoryDBContext(); switch (SearchType) { case UserSearchType.UserId: { int id = 0; if (int.TryParse(value, out id)) { var _user = contaxt.Users.Where(p => p.UserId == id).ToList(); List.AddRange(_user); } return(List); } case UserSearchType.RegisterDate: { var _user = contaxt.Users.Where(p => p.RegisterDate == DateTime.Parse(value)).ToList(); List.AddRange(_user); return(List); } case UserSearchType.Username: { var _user = contaxt.Users.Where(p => p.Username.Contains(value)).ToList(); List.AddRange(_user); return(List); } case UserSearchType.All: { var _user = contaxt.Users.Where(p => p.RegisterDate == DateTime.Parse(value)).ToList(); List.AddRange(_user); _user = contaxt.Users.Where(p => p.Username.Contains(value)).ToList(); List.AddRange(_user); int id = 0; if (int.TryParse(value, out id)) { _user = contaxt.Users.Where(p => p.UserId == id).ToList(); List.AddRange(_user); } return(List); } default: { return(null); } } }
public Product Find(int id) { try { var contaxt = new DataLayer.InventoryDBContext(); return(contaxt.Products.Where(p => p.ProductId == id).FirstOrDefault()); } catch { return(null); } }
public bool Update(User user) { try { var contaxt = new DataLayer.InventoryDBContext(); var _user = contaxt.Users.FirstOrDefault(p => p.UserId == user.UserId); _user = user; contaxt.SaveChanges(); return(true); } catch { return(true); } }
public static async Task <bool> InitialDataBase() { return(await Task <bool> .Run(() => { try { var dbcontext = new DataLayer.InventoryDBContext(); dbcontext.Database.Initialize(false); return true; } catch { return false; } })); }
public bool Add(Product product) { try { var contaxt = new DataLayer.InventoryDBContext(); product.CreatedDate = DateTime.Now; product.CreatedByUserId = DatabaseTools.GetUserID; contaxt.Products.Add(product); contaxt.SaveChanges(); return(true); } catch { return(false); } }
public bool Add(User user) { try { var contaxt = new DataLayer.InventoryDBContext(); user.RegisterDate = DateTime.Now; user.Deleted = false; contaxt.Users.Add(user); contaxt.SaveChanges(); return(true); } catch { return(false); } }
public InventoryInsTypeRepositoryTests() { var contaxt = new DataLayer.InventoryDBContext(); var relateduser = contaxt.Users.FirstOrDefault(u => u.Username.Equals("admin")); var identity = new GenericIdentity(relateduser.Username); var roles = relateduser.Roles.Select(p => p.Title).ToArray(); var principal = new GenericPrincipal(identity, roles); System.Threading.Thread.CurrentPrincipal = principal; _InventoryInsType = new Repositories.InventoryInsTypeRepository(); EInventoryInsType = new Entities.InventoryInsType() { Title = "Title", Description = "Description", }; }
public bool Update(Inventory inventory) { try { var contaxt = new DataLayer.InventoryDBContext(); var _inventory = contaxt.Inventories.FirstOrDefault(p => p.InventoryId == inventory.InventoryId); _inventory = inventory; _inventory.ChangedDate = DateTime.Now; _inventory.ChangedByUserId = DatabaseTools.GetUserID; contaxt.SaveChanges(); return(true); } catch { return(true); } }
public bool Delete(int id) { try { var contaxt = new DataLayer.InventoryDBContext(); var product = contaxt.Products.Where(p => p.ProductId == id).FirstOrDefault(); product.Deleted = true; product.DeletedDate = DateTime.Now; product.DeletedByUserId = DatabaseTools.GetUserID; contaxt.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(Product product) { try { var contaxt = new DataLayer.InventoryDBContext(); var _product = contaxt.Products.Where(p => p.ProductId == product.ProductId).FirstOrDefault(); _product = product; _product.ChangedDate = DateTime.Now; _product.ChangedByUserId = DatabaseTools.GetUserID; contaxt.SaveChanges(); return(true); } catch { return(false); } }
public InventoryInsDeatilRepositoryTests() { var contaxt = new DataLayer.InventoryDBContext(); var relateduser = contaxt.Users.FirstOrDefault(u => u.Username.Equals("admin")); var identity = new GenericIdentity(relateduser.Username); var roles = relateduser.Roles.Select(p => p.Title).ToArray(); var principal = new GenericPrincipal(identity, roles); System.Threading.Thread.CurrentPrincipal = principal; _InventoryInsDeatil = new Repositories.InventoryInsDeatilRepository(); EInventoryInsDeatil = new Entities.InventoryInsDeatil() { InventoryInsHeaderId = 1, ProductId = 1, Amount = 1, }; }
public bool Update(ProductUnit unit) { try { var contaxt = new DataLayer.InventoryDBContext(); var _unit = contaxt.ProductUnits.FirstOrDefault(p => p.ProductUnitId == unit.ProductUnitId); _unit = unit; _unit.ChangedByUserId = DatabaseTools.GetUserID; _unit.ChangedDate = DateTime.Now; contaxt.SaveChanges(); return(true); } catch { return(true); } }
public bool Add(Inventory inventory) { try { var contaxt = new DataLayer.InventoryDBContext(); inventory.Deleted = false; inventory.CreatedByUserId = DatabaseTools.GetUserID; inventory.CreatedDate = DateTime.Now; contaxt.Inventories.Add(inventory); contaxt.SaveChanges(); return(true); } catch { return(false); } }
public ProductParameterValueRepositoryTests() { var contaxt = new DataLayer.InventoryDBContext(); var relateduser = contaxt.Users.FirstOrDefault(u => u.Username.Equals("admin")); var identity = new GenericIdentity(relateduser.Username); var roles = relateduser.Roles.Select(p => p.Title).ToArray(); var principal = new GenericPrincipal(identity, roles); System.Threading.Thread.CurrentPrincipal = principal; _ProductParameterValue = new Repositories.ProductParameterValueRepository(); EProductParameterValue = new Entities.ProductParameterValue() { ProductId = 1, ProductParameterId = 1, Value = "Value", }; }
public bool Delete(int id) { try { var contaxt = new DataLayer.InventoryDBContext(); var user = contaxt.Users.FirstOrDefault(p => p.UserId == id); user.Deleted = true; user.DeletedByUserId = DatabaseTools.GetUserID; user.DeletedDate = DateTime.Now; contaxt.SaveChanges(); return(true); } catch { return(true); } }
public ICollection <ProductUnit> Search(ProductUnitSearchType SearchType, string value) { List <ProductUnit> List = new List <ProductUnit>(); var contaxt = new DataLayer.InventoryDBContext(); switch (SearchType) { case ProductUnitSearchType.id: { int id = 0; if (int.TryParse(value, out id)) { var _unit = contaxt.ProductUnits.Where(p => p.ProductUnitId == id).ToList(); List.AddRange(_unit); } return(List); } case ProductUnitSearchType.title: { var _unit = contaxt.ProductUnits.Where(p => p.Title.Contains(value)).ToList(); List.AddRange(_unit); return(List); } case ProductUnitSearchType.All: { var _unit = contaxt.ProductUnits.Where(p => p.Title.Contains(value)).ToList(); List.AddRange(_unit); int id = 0; if (int.TryParse(value, out id)) { _unit = contaxt.ProductUnits.Where(p => p.ProductUnitId == id).ToList(); List.AddRange(_unit); } return(List); } default: { return(null); } } }
public ProductCategoryRepositoryTests() { var contaxt = new DataLayer.InventoryDBContext(); var relateduser = contaxt.Users.FirstOrDefault(u => u.Username.Equals("admin")); var identity = new GenericIdentity(relateduser.Username); var roles = relateduser.Roles.Select(p => p.Title).ToArray(); var principal = new GenericPrincipal(identity, roles); System.Threading.Thread.CurrentPrincipal = principal; procat = new ProductCategoryRepository(); Eprocat = new Entities.ProductCategory() { SubProductCategoryID = 0, InventoryId = 1, Title = "Title", Description = "Description", Capacity = 1, }; }
public InventoryInsHeaderRepository() { contaxt = new DataLayer.InventoryDBContext(); }
public InventoryOutsDeatilRepository() { contaxt = new DataLayer.InventoryDBContext(); }
public ICollection <Inventory> Search(InventorySearchType SearchType, string value) { List <Inventory> List = new List <Inventory>(); var contaxt = new DataLayer.InventoryDBContext(); switch (SearchType) { case InventorySearchType.All: { //search by address var _Inventory = contaxt.Inventories.Where(p => p.Address.Contains(value)).ToList(); List.AddRange(_Inventory); //search by title _Inventory = contaxt.Inventories.Where(p => p.Title.Contains(value)).ToList(); List.AddRange(_Inventory); //search by Telephone _Inventory = contaxt.Inventories.Where(p => p.Telephone.Contains(value)).ToList(); List.AddRange(_Inventory); //search by id int id = 0; if (int.TryParse(value, out id)) { _Inventory = contaxt.Inventories.Where(p => p.InventoryId == id).ToList(); List.AddRange(_Inventory); } return(List); } case InventorySearchType.inventoryId: { //search by id int id = 0; if (int.TryParse(value, out id)) { var _Inventory = contaxt.Inventories.Where(p => p.InventoryId == id).ToList(); List.AddRange(_Inventory); } return(List); } case InventorySearchType.title: { //search by title var _Inventory = contaxt.Inventories.Where(p => p.Title.Contains(value)).ToList(); List.AddRange(_Inventory); return(List); } case InventorySearchType.Address: { //search by address var _Inventory = contaxt.Inventories.Where(p => p.Address.Contains(value)).ToList(); List.AddRange(_Inventory); return(List); } case InventorySearchType.Telephone: { //search by Telephone var _Inventory = contaxt.Inventories.Where(p => p.Telephone.Contains(value)).ToList(); List.AddRange(_Inventory); return(List); } default: { return(null); } } }
public ProductParameterValueRepository() { contaxt = new DataLayer.InventoryDBContext(); }
public RoleRepository() { contaxt = new DataLayer.InventoryDBContext(); }
public ProductUnitRepository() { contaxt = new DataLayer.InventoryDBContext(); }
public CorporationRepository() { contaxt = new DataLayer.InventoryDBContext(); }
public ICollection <Product> Search(ProductSearchType SearchType, string value) { List <Product> List = new List <Product>(); var contaxt = new DataLayer.InventoryDBContext(); switch (SearchType) { case ProductSearchType.All: { //search by title var _product = contaxt.Products.Where(p => p.Title.Contains(value)).ToList(); List.AddRange(_product); //search by id int id = 0; if (int.TryParse(value, out id)) { _product = contaxt.Products.Where(p => p.ProductId == id).ToList(); List.AddRange(_product); } //search by code int code = 0; if (int.TryParse(value, out code)) { _product = contaxt.Products.Where(p => p.Code == code).ToList(); List.AddRange(_product); } return(List); } case ProductSearchType.CorporationId: { //search by id int id = 0; if (int.TryParse(value, out id)) { var _product = contaxt.Products.Where(p => p.ProductId == id).ToList(); List.AddRange(_product); } return(List); } case ProductSearchType.Title: { //search by title var _product = contaxt.Products.Where(p => p.Title.Contains(value)).ToList(); List.AddRange(_product); return(List); } case ProductSearchType.code: { int code = 0; if (int.TryParse(value, out code)) { var _product = contaxt.Products.Where(p => p.Code == code).ToList(); List.AddRange(_product); } return(List); } default: { return(null); } } }