public bool IsLoginNameExist(string loginName)
 {
     using (SampleEntities db = new SampleEntities())
     {
         return db.SYSUsers.Where(o => o.LoginName.Equals(loginName)).Any();
     }
 }
        public void UpdateProduct(ProductView pv)
        {
            using (SampleEntities db = new SampleEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Product _product = db.Products.Find(pv.Id);

                        if(_product!=null)
                        {
                            _product.ProductDescription = pv.ProductDescription;
                            _product.ProductName = pv.ProductName;
                            _product.ProductProce = pv.ProductProce;
                            _product.UpdateBy = pv.UpdateBy;
                            _product.UpdatedDate = pv.UpdatedDate;
                            db.SaveChanges();   
                        }
                        dbContextTransaction.Commit();
                    }
                    catch(Exception ex)
                    {
                        dbContextTransaction.Rollback();    
                    }
                }
            }
        }
 public string GetUserPassword(string loginName)
 {
     using (SampleEntities db = new SampleEntities())
     {
         var user = db.SYSUsers.Where(o => o.LoginName.ToLower().Equals(loginName));
         if (user.Any())
             return user.FirstOrDefault().PasswordEncryptedText;
         else
             return string.Empty;
     }
 }
 public void AddProduct(ProductView pv)
 {
     using (SampleEntities db = new SampleEntities())
     {
         Product p = new Product();
         p.ProductName = pv.ProductName;
         p.ProductProce = pv.ProductProce;
         p.ProductDescription = pv.ProductDescription;
         p.CreatedBy = pv.CreatedBy;
         p.CreatedDate = pv.CreatedDate;
         p.UpdateBy = pv.UpdateBy;
         p.UpdatedDate = pv.UpdatedDate;
         db.Products.Add(p);
         db.SaveChanges();
     }
 }
        public void AddUserAccount(UserSignUpView user)
        {

            using (SampleEntities db = new SampleEntities())
            {

                SYSUser SU = new SYSUser();
                SU.LoginName = user.LoginName;
                SU.PasswordEncryptedText = user.Password;
                SU.RowCreatedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SU.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1; ;
                SU.RowCreatedDateTime = DateTime.Now;
                SU.RowMOdifiedDateTime = DateTime.Now;

                db.SYSUsers.Add(SU);
                db.SaveChanges();

                SYSUserProfile SUP = new SYSUserProfile();
                SUP.SYSUserID = SU.SYSUserID;
                SUP.FirstName = user.FirstName;
                SUP.LastName = user.LastName;
                SUP.Gender = user.Gender;
                SUP.RowCreatedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SUP.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                SUP.RowCreatedDateTime = DateTime.Now;
                SUP.RowModifiedDateTime = DateTime.Now;

                db.SYSUserProfiles.Add(SUP);
                db.SaveChanges();


                if (user.LOOKUPRoleID > 0)
                {
                    SYSUserRole SUR = new SYSUserRole();
                    SUR.LOOKUPRoleID = user.LOOKUPRoleID;
                    SUR.SYSUserID = user.SYSUserID;
                    SUR.IsActive = true;
                    SUR.RowCreatedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                    SUR.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1;
                    SUR.RowCreatedDateTime = DateTime.Now;
                    SUR.RowModifiedDateTime = DateTime.Now;

                    db.SYSUserRoles.Add(SUR);
                    db.SaveChanges();
                }
            }
        }
        public ProductView SelectProduct(int id)
        {
            ProductView _pv = null;
            using (SampleEntities db = new SampleEntities())
            {
                Product _product = db.Products.Find(id);

                if (_product != null)
                {
                    _pv = new ProductView();
                    _pv.ProductDescription = _product.ProductDescription;
                    _pv.ProductName = _product.ProductName;
                    _pv.ProductProce = _product.ProductProce;
                    _pv.UpdateBy = _product.UpdateBy;
                    _pv.UpdatedDate = _product.UpdatedDate;
                }
            }
            return _pv;
        }
        public List<ProductView> SelectAllListProducts()
        {
            List<ProductView> products = new List<ProductView>();
            using (SampleEntities db = new SampleEntities())
            {
                
                var _products = db.Products.ToList();
                foreach(Product _p in _products)
                {
                    ProductView pv = new ProductView();
                    pv.Id = _p.Id;
                    pv.ProductName = _p.ProductName;
                    pv.ProductProce = _p.ProductProce;
                    pv.ProductDescription = _p.ProductDescription;
                    products.Add(pv);
                }
                     
            }

            return products;
        }