Ejemplo n.º 1
0
        public IHttpActionResult ChangePassword([FromBody]Login login)
        {
            //1. Get student from DB
            Login loginGetdata = new Login();
            using (var ctx = new InventoryManagementDBEntities())
            {
                loginGetdata = ctx.Logins.Where(s => s.user_name == login.user_name).FirstOrDefault<Login>();
            }

            //2. change student name in disconnected mode (out of ctx scope)
            if (loginGetdata != null)
            {
                loginGetdata.password = login.password;
            }

            //save modified entity using new Context
            using (var dbCtx = new InventoryManagementDBEntities())
            {
                //3. Mark entity as modified
                dbCtx.Entry(loginGetdata).State = System.Data.Entity.EntityState.Modified;

                //4. call SaveChanges
                dbCtx.SaveChanges();
                return Ok(login);
            }
        }
Ejemplo n.º 2
0
        public Boolean UpdateData(Login login)
        {
            //1. Get student from DB
            Login loginGetdata = new Login();
            using (var ctx = new InventoryManagementDBEntities())
            {
                loginGetdata = ctx.Logins.Where(s => s.User_ID == login.User_ID).FirstOrDefault<Login>();
            }

            //2. change student name in disconnected mode (out of ctx scope)
            if (loginGetdata != null)
            {
                loginGetdata.user_name = login.user_name;
            }

            //save modified entity using new Context
            using (var dbCtx = new InventoryManagementDBEntities())
            {
                //3. Mark entity as modified
                dbCtx.Entry(loginGetdata).State = System.Data.Entity.EntityState.Modified;

                //4. call SaveChanges
                dbCtx.SaveChanges();
            }
            return true;
        }
Ejemplo n.º 3
0
        public Boolean GetUserName([FromUri]Login login)
        {
            Login loginGetdata = new Login();
            using (var ctx = new InventoryManagementDBEntities())
            {
                loginGetdata = ctx.Logins.Where(s => s.user_name == login.user_name) .FirstOrDefault();
            }

            //2. change student name in disconnected mode (out of ctx scope)
            if (loginGetdata != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult Savedata1(Login login)
        {
            // create new Student entity object in disconnected scenario (out of the scope of DbContext)
            //var login = new Login();

            //set student name
            //login.Name = "testing";

            //create DBContext object
            using (var dbCtx = new InventoryManagementDBEntities())
            {
                //Add Student object into Students DBset
                dbCtx.Logins.Add(login);

                // call SaveChanges method to save student into database
                dbCtx.SaveChanges();
            }
            return Ok(login);
        }
Ejemplo n.º 5
0
        public IHttpActionResult GetLoginsSucessUserID([FromUri]Login login)
        {
            Login loginGetdata = new Login();
            using (var ctx = new InventoryManagementDBEntities())
            {
                loginGetdata = ctx.Logins.Where(s => s.password == login.password && s.user_name == login.user_name).FirstOrDefault();
            }

            //2. change student name in disconnected mode (out of ctx scope)
            if (loginGetdata != null)
            {
                login.User_ID = loginGetdata.User_ID;
                return Ok(login);
            }
            else
            {
                return Ok(login);
            }
        }