Пример #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);
            }
        }
Пример #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;
        }