Beispiel #1
0
 public bool insert(Products entity)
 {
     using (var db = new ProductWithQRCodeDbContext())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Products _pro = db.Products.OrderByDescending(u => u.ID).FirstOrDefault();
                 if (_pro != null)
                 {
                     entity.ID = _pro.ID + 1;
                 }
                 else
                 {
                     entity.ID = 1;
                 }
                 db.Products.Add(entity);
                 db.SaveChanges();
                 dbContextTransaction.Commit();
                 return(true);
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(false);
             }
         }
     }
 }
Beispiel #2
0
 public Categories GetById(int id)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Categories.Where(x => x.Status == true && x.ID == id).SingleOrDefault());
     }
 }
Beispiel #3
0
 public dynamic GetById(int id)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Products.Where(x => x.ID == id)
                .Select(x => new
         {
             ID = x.ID,
             Name = x.Name,
             Intro = x.Intro,
             Content = x.Content,
             Image = x.Image,
             Price = x.Price,
             Discount = x.Discount,
             ListImage = x.ListImage,
             CreateBy = x.CreateBy,
             CreateDate = x.CreateDateTime,
             Meta = x.Meta,
             CateID = x.CateID,
             Lang = x.Lang,
             Status = x.Status,
             QRCode = x.QRCode,
             Tag = x.Tag
         }).Single());
     }
 }
Beispiel #4
0
 public dynamic delete(string _maNhanVien)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec Users_delete @id",
                                                       new SqlParameter("@id", _maNhanVien)).Single());
     }
 }
Beispiel #5
0
 public List <Products> GetByCateId(int cateId)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         var product = db.Products.Where(x => x.Status == true && x.CateID.Contains(":" + cateId + ":")).ToList();
         return(product);
     }
 }
Beispiel #6
0
 public Products GetByMeta(string meta)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         var product = db.Products.Where(x => x.Status == true && x.Meta.Contains(meta)).SingleOrDefault();
         return(product);
     }
 }
 public dynamic delete(string _maTaiKhoan)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec TaiKhoan_delete @maTaiKhoan",
                                                       new SqlParameter("@maTaiKhoan", _maTaiKhoan)).Single());
     }
 }
Beispiel #8
0
 public dynamic getByUsernamePassword(string _username, string _password)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <AccountSession>("exec Users_getByUsernamePassword @username, @password",
                                                      new SqlParameter("@username", _username),
                                                      new SqlParameter("@password", _password)).Single());
     }
 }
Beispiel #9
0
 public dynamic resetPass(string _username, string _birthday)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec Users_Resetpass @username, @birthday",
                                                       new SqlParameter("@username", _username),
                                                       new SqlParameter("@birthday", DateTime.Parse(_birthday))).Single());
     }
 }
Beispiel #10
0
 public List <Products> GetByCateMeta(string meta)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         int cateId  = db.Categories.Where(x => x.Meta.Contains(meta)).Single().ID;
         var product = db.Products.Where(x => x.Status == true && x.CateID.Contains(":" + cateId + ":")).ToList();
         return(product);
     }
 }
 public dynamic insert(Modules entity)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec NhomChucNang_insert @tenChucNang, @tinhTrang",
                                                       new SqlParameter("@tenChucNang", entity.Name),
                                                       new SqlParameter("@tinhTrang", entity.Status)).Single());
     }
 }
Beispiel #12
0
 public dynamic Login(string _username, string _password)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec Pro_Login @username, @password",
                                                       new SqlParameter("@username", _username),
                                                       new SqlParameter("@password", _password)).Single());
     }
 }
Beispiel #13
0
 public dynamic update(GroupsUser entity)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec TaiKhoan_update @maTaiKhoan, @tenTaiKhoan, @tinhTrang",
                                                       new SqlParameter("@maTaiKhoan", entity.ID),
                                                       new SqlParameter("@tenTaiKhoan", entity.Name),
                                                       new SqlParameter("@tinhTrang", entity.Status)).Single());
     }
 }
Beispiel #14
0
 public dynamic changePass(string _username, string _oldpass, string _newpass)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec Users_ChangePassword @username, @password, @newpass",
                                                       new SqlParameter("@username", _username),
                                                       new SqlParameter("@password", _oldpass),
                                                       new SqlParameter("@newpass", _newpass)).Single());
     }
 }
 public dynamic getAll()
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Modules.Where(x => x.Status == true)
                .Select(x => new
         {
             ID = x.ID,
             Name = x.Name
         }).ToList());
     }
 }
Beispiel #16
0
 public dynamic getAll()
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.GroupsUser.Where(x => x.Status == true)
                .Select(x => new
         {
             MaTaiKhoan = x.ID,
             TenTaiKhoan = x.Name
         }).ToList());
     }
 }
Beispiel #17
0
 public List <Products> GetRecentProduct()
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         var listProduct = db.Products.Where(x => x.Status == true).Take(12);
         if (listProduct != null)
         {
             return(listProduct.ToList());
         }
         return(null);
     }
 }
Beispiel #18
0
 public dynamic getUserType()
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.GroupsUser.OrderByDescending(x => x.ID)
                .Where(x => x.Status == true)
                .Select(x => new
         {
             ID = x.ID,
             name = x.Name
         }).ToList());
     }
 }
Beispiel #19
0
 public dynamic update(Users entity)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Database.SqlQuery <ExecQueryResult>("exec Users_update @id, @fullname, @gender, @birthday, @phone, @type, @status",
                                                       new SqlParameter("@id", entity.ID),
                                                       new SqlParameter("@fullname", entity.Name),
                                                       new SqlParameter("@gender", entity.Gender),
                                                       new SqlParameter("@birthday", entity.Birthday),
                                                       new SqlParameter("@phone", entity.Phone),
                                                       new SqlParameter("@type", entity.GroupID),
                                                       new SqlParameter("@status", entity.Status)).Single());
     }
 }
Beispiel #20
0
 public bool check(int _maTaiKhoan, int permission, int action)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         var valuePermiss = db.Permissions.SingleOrDefault(x => x.GroupID == _maTaiKhoan && x.FunctionalID == permission);
         if (valuePermiss != null)
         {
             if (valuePermiss.ValueRights > 0 && action > 0)
             {
                 return((valuePermiss.ValueRights & action) > 0);
             }
             return(false);
         }
         return(false);
     }
 }
Beispiel #21
0
 public dynamic GetAll(int type)
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Categories.OrderByDescending(x => x.ID)
                .Where(x => x.Type == type)
                .Select(x => new
         {
             ID = x.ID,
             Name = x.Name,
             Meta = x.Meta,
             Parent = x.Parent,
             ParentName = db.Categories.Where(y => y.ID == x.Parent).FirstOrDefault().Name,
             Image = x.Image,
             Status = x.Status,
             Type = x.Type
         }).ToList());
     }
 }
Beispiel #22
0
 public bool update(Products entity)
 {
     using (var db = new ProductWithQRCodeDbContext())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try{
                 db.Products.Attach(entity);
                 db.Entry(entity).State = EntityState.Modified;
                 db.SaveChanges();
                 dbContextTransaction.Commit();
                 return(true);
             }
             catch (Exception) {
                 dbContextTransaction.Rollback();
                 return(false);
             }
         }
     }
 }
Beispiel #23
0
 public bool Insert(Categories entity)
 {
     using (var db = new ProductWithQRCodeDbContext())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 db.Categories.Add(entity);
                 db.SaveChanges();
                 dbContextTransaction.Commit();
                 return(true);
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(false);
             }
         }
     }
 }
Beispiel #24
0
 public dynamic getAll()
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Users.OrderByDescending(x => x.ID)
                .Where(x => x.Status == true)
                .Select(x => new
         {
             ID = x.ID,
             name = x.Name,
             gender = x.Gender,
             birthday = x.Birthday,
             phone = x.Phone,
             groupId = x.GroupID,
             username = x.Username,
             password = x.Password,
             group = x.GroupsUser.Name,
             status = x.Status
         }).ToList());
     }
 }
Beispiel #25
0
 public bool UpdateMultiRecords(int[] idList)
 {
     using (var db = new ProductWithQRCodeDbContext())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 var categories = db.Categories.Where(x => idList.Contains(x.ID)).ToList();
                 categories.ForEach(a => a.Status = false);
                 db.SaveChanges();
                 dbContextTransaction.Commit();
                 return(true);
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(false);
             }
         }
     }
 }
Beispiel #26
0
 public int Delete(int _cateId)
 {
     using (var db = new ProductWithQRCodeDbContext())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 var category = db.Categories.Find(_cateId);
                 category.Status = false;
                 db.Categories.Attach(category);
                 db.Entry(category).State = EntityState.Modified;
                 db.SaveChanges();
                 dbContextTransaction.Commit();
                 return((int)category.Type);
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(0);
             }
         }
     }
 }
Beispiel #27
0
 public dynamic GetAll()
 {
     using (ProductWithQRCodeDbContext db = new ProductWithQRCodeDbContext())
     {
         return(db.Products.OrderByDescending(x => x.ID)
                .Select(x => new
         {
             ID = x.ID,
             Name = x.Name,
             Intro = x.Intro,
             Content = x.Content,
             Image = x.Image,
             Price = x.Price,
             Discount = x.Discount,
             ListImage = x.ListImage,
             CreateBy = x.Users.Name,
             CreateDate = x.CreateDateTime,
             Meta = x.Meta,
             CateID = x.CateID,
             Status = x.Status,
             QRCode = x.QRCode
         }).ToList());
     }
 }
Beispiel #28
0
 public bool delete(int _proId)
 {
     using (var db = new ProductWithQRCodeDbContext())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 var product = db.Products.SingleOrDefault(x => x.ID == _proId);
                 product.Status = false;
                 db.Products.Attach(product);
                 db.Entry(product).State = EntityState.Modified;
                 db.SaveChanges();
                 dbContextTransaction.Commit();
                 return(true);
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
                 return(false);
             }
         }
     }
 }