Exemplo n.º 1
0
 public GoodDTO UpdateProd(GoodDTO productToUpdate)
 {
     using (var db = new companyEntities())
     {
         var prod = db.tblGoods.FirstOrDefault(u => u.id == productToUpdate.id);
         return(_mapper.Map <GoodDTO>(prod));
     }
 }
Exemplo n.º 2
0
 public UserDTO GetUserById(int id)
 {
     using (var entities = new companyEntities())
     {
         var us = entities.tblUsers.FirstOrDefault(c => c.id == id);
         return(_mapper.Map <UserDTO>(us));
     }
 }
Exemplo n.º 3
0
        public List <UserDTO> GetUsers()
        {
            List <UserDTO> users = new List <UserDTO>();

            using (var entities = new companyEntities())
            {
                users = _mapper.Map <List <UserDTO> >(entities.tblUsers).ToList();
            }
            return(users);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 创建EF上下文对象,已存在就直接取,不存在就创建,保证线程内是唯一。
        /// </summary>
        /// <returns></returns>
        public static DbContext Create()
        {
            DbContext dbContext = CallContext.GetData("DbContext") as DbContext;

            if (dbContext == null)
            {
                dbContext = new companyEntities();
                CallContext.SetData("DbContext", dbContext);
            }
            return(dbContext);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            companyEntities entites   = new companyEntities();
            List <Employee> employees = entites.Employees.ToList();

            foreach (var item in employees)
            {
                Console.WriteLine($"{item.EmpID},{item.EmpName}");
            }

            Console.ReadKey();
        }
Exemplo n.º 6
0
 public UserDTO UpdateUser(UserDTO userToupdate)
 {
     using (var db = new companyEntities())
     {
         var user = db.tblUsers.FirstOrDefault(u => u.id == userToupdate.id);
         user.email      = userToupdate.email;
         user.first_name = userToupdate.first_name;
         user.last_name  = userToupdate.last_name;
         user.Is_Login   = true;
         user.password   = userToupdate.password;
         return(_mapper.Map <UserDTO>(user));
     }
 }
Exemplo n.º 7
0
 public int DeleteUserById(int id)
 {
     using (var db = new companyEntities())
     {
         tblUser user = _mapper.Map <tblUser>(GetUserById(id));
         if (user != null)
         {
             db.Entry(user).State = EntityState.Deleted;
             db.SaveChanges();
             return(1);
         }
         return(0);
     }
 }
Exemplo n.º 8
0
        public int AddUser(UserDTO user)
        {
            if (user != null)
            {
                using (var db = new companyEntities())
                {
                    db.tblUsers.Add(_mapper.Map <tblUser>(user));
                    db.SaveChanges();
                    return(user.id);
                }
            }

            return(0);
        }
Exemplo n.º 9
0
        public int AddProd(GoodDTO prod)
        {
            if (prod != null)
            {
                using (var db = new companyEntities())
                {
                    db.tblGoods.Add(_mapper.Map <tblGood>(prod));
                    db.SaveChanges();
                    return(prod.id);
                }
            }

            return(0);
        }
Exemplo n.º 10
0
        public int Login(string email, string pass)
        {
            int    res      = -1;
            string passHash = GetHash(pass);

            using (var entities = new companyEntities())
            {
                var user = entities.tblUsers.Where(u => u.email == email && u.password == passHash).FirstOrDefault();
                if (user != null)
                {
                    res           = user.id;
                    user.Is_Login = true;
                    SaveChanges();
                    return(res);
                }
            }

            return(res);
        }